SQL > SQL Syntax

In this page, we list the SQL syntax for each of the SQL commands in this tutorial, making this an easy reference for someone to learn SQL. For detailed explanations of each SQL syntax, please go to the individual section by clicking on the keyword.

The purpose of this page is to have a quick reference page for SQL syntax, so you can learn SQL more quickly. Bookmark this page now by pressing Control-D so you can have this syntax page handy. You can also download a 1-page PDF version here.

Select Statement
SELECT "column_name" FROM "table_name";

SELECT DISTINCT "column_name"
FROM "table_name";

SELECT "column_name"
FROM "table_name"
WHERE "condition";

SELECT "column_name"
FROM "table_name"
WHERE "simple condition"
{[AND|OR] "simple condition"}+;

SELECT "column_name"
FROM "table_name"
WHERE "column_name" IN ('value1', 'value2', ...);

SELECT "column_name"
FROM "table_name"
WHERE "column_name" BETWEEN 'value1' AND 'value2';

SELECT "column_name"
FROM "table_name"
WHERE "column_name" LIKE {PATTERN};

Order By
SELECT "column_name"
FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC];

SELECT COUNT("column_name")
FROM "table_name";

Group By
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1";

SELECT "column_name1", [Function("column_name2")]
FROM "table_name"
[GROUP BY "column_name1"]
HAVING (arithematic function condition);

Create Table Statement
CREATE TABLE "table_name"
("column 1" "data type for column 1" [column 1 constraint(s)],
"column 2" "data type for column 2" [column 2 constraint(s)],
[table constraint(s)]);

Drop Table Statement
DROP TABLE "table_name";

Truncate Table Statement
TRUNCATE TABLE "table_name";

Insert Into Statement
INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...);

Insert Into Select Statement
INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2";

Update Statement
UPDATE "table_name"
SET "column_1" = [new value]
WHERE "condition";

Delete From Statement
DELETE FROM "table_name"
WHERE "condition";

This page was last updated on June 19, 2023.

Copyright © 2024   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact