รวมคำสั่ง SQL ต่าง ๆ ที่ใช้บ่อย ๆ เอาไว้กันลืม

| Database-SQL | 850 | 903 วันที่แล้ว
บทความนี้เป็นการรวบรวมคำสั่ง SQL ต่าง ๆ ที่ใช้กันบ่อย ๆ สำหรับใครที่ลืม Syntax

SQL SELECT Statement
SELECT column1, column2....columnN
FROM   table_name;
SQL DISTINCT Clause
SELECT DISTINCT column1, column2....columnN
FROM   table_name;
SQL WHERE Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION;
SQL AND/OR Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION-1 {AND|OR} CONDITION-2;
SQL IN Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name IN (val-1, val-2,...val-N);
SQL BETWEEN Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name BETWEEN val-1 AND val-2;
SQL LIKE Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name LIKE { PATTERN };
SQL ORDER BY Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION
ORDER BY column_name {ASC|DESC};
SQL GROUP BY Clause
SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name;
SQL COUNT Clause
SELECT COUNT(column_name)
FROM   table_name
WHERE  CONDITION;
SQL HAVING Clause
SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name
HAVING (arithematic function condition);
SQL CREATE TABLE Statement
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
SQL DROP TABLE Statement
DROP TABLE table_name;
SQL CREATE INDEX Statement
CREATE UNIQUE INDEX index_name
ON table_name ( column1, column2,...columnN);
SQL DROP INDEX Statement
ALTER TABLE table_name
DROP INDEX index_name;
SQL DESC Statement
DESC table_name;
SQL TRUNCATE TABLE Statement
TRUNCATE TABLE table_name;
SQL ALTER TABLE Statement
ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};
SQL ALTER TABLE Statement (Rename)
ALTER TABLE table_name RENAME TO new_table_name;
SQL INSERT INTO Statement
INSERT INTO table_name( column1, column2....columnN)
VALUES ( value1, value2....valueN);
SQL UPDATE Statement
UPDATE table_name
SET column1 = value1, column2 = value2....columnN=valueN
[ WHERE  CONDITION ];
SQL DELETE Statement
DELETE FROM table_name
WHERE  {CONDITION};
SQL CREATE DATABASE Statement
CREATE DATABASE database_name;
SQL DROP DATABASE Statement
DROP DATABASE database_name;
SQL USE Statement
USE database_name;
SQL COMMIT Statement
COMMIT;
SQL ROLLBACK Statement
ROLLBACK;
comments

[1]
Adobe-PDF
1103 D
[1]
Android
994 D
[40]
Animal
1087 D
[1]
Apache
1103 D
[2]
[1]
[10]
CMS-Joomla
1104 D
[2]
CMS-SMF
1104 D
[1]
[1]
[1]
[3]
[1]
Database
1103 D
[4]
[1]
Docker
999 D
[1]
[1]
Fruit
1087 D
[2]
Git
890 D
[5]
HTML
890 D
[1]
Housework
1092 D
[2]
IT
1084 D
[2]
Imacro
1104 D
[17]
Java
887 D
[1]
Java-Web
994 D
[1]
[2]
MQL5
916 D
[3]
MakeMoney
889 D
[18]
[1]
[1]
Maven
888 D
[5]
[1]
Mobile
1101 D
[1]
NodeJs
890 D
[3]
Physics
885 D
[4]
PugJS
890 D
[2]
React
899 D
[132]
Science
1086 D
[1]
[2]
Spring
888 D
[12]
[7]
[2]
[1]
[4]
Ubuntu
1054 D
[1]
WebLogic
1085 D
[4]