WITH
WITH query_tab_name AS (
SELECT ....
)
SELECT ...
FROM query_tab_name ....
|
Full Syntax Order
SELECT [ DISTINCT ]
expressions
FROM tables
[JOIN other_table ON conditions]
[WHERE conditions]
[GROUP BY expressions]
[HAVING conditions]
[ORDER BY expression [ ASC | DESC ]]
[LIMIT number_rows OFFSET offset_value];
|
CASE WHEN
CASE WHEN contionion THEN x WHEN condition2 THEN y ELSE z END
|
JOINS
SQL_Server & Oracle
[INNER] JOIN
LEFT [OUTER] JOIN
RIGHT [OUTER] JOIN
FULL [OUTER] JOIN
CROSS JOIN -- cartesian_join
example:
SELECT * FROM tabA INNER JOIN tabB ON tabA .id = tabB .id;
|
Conditions
|
|
column LIKE pattern -- eg. ‘%value%’
|
|
|
UPDATE
UPDATE table
SET column1 = expression1,
column2 = expression2,
...
[WHERE conditions];
UPDATE table1
SET column1 = (SELECT expression1
FROM table2
WHERE conditions)
[WHERE conditions];
UPDATE table1, table2, ...
SET column1 = expression1,
column2 = expression2,
...
WHERE table1.column = table2.column
[AND conditions];
|
Functions
STRCMP("str1","str2")
|
Compare strings |
|
|
|
Left trim |
SUBSTRING("str","inx1","inx2")
|
Substring of a string |
CONCAT("str1","str2")
|
Concatenate |
|
round number |
|
|
INSERT
INSERT INTO table
(column1, column2, ... column_n )
VALUES
(expression1, expression2, ... expression_n );
INSERT INTO table
(column1, column2, ... )
SELECT expression1, expression2, ...
FROM source_table
[WHERE conditions];
|
EXCEPT
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions]
EXCEPT
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions];
|
CREATE
CREATE TABLE table_name (
id INT AUTO_INCREMENT,
name VARCHAR(2),
surname VARCHAR(32),
PRIMARY KEY (id)
);
|
ALTER TABLE
ALTER TABLE table ADD COLUMN column;
ALTER TABLE table DROP COLUMN column;
ALTER TABLE table ADD PRIMARY KEY (column);
|
DELETE
DELETE FROM table
[WHERE conditions];
|
|