sql query commands cheat sheet code example
Example: sql cheat sheet
SELECT * FROM table_name;
SELECT DISTINCT column_name;
SELECT column1, column2 FROM table_name WHERE condition;
SELECT * FROM table_name WHERE condition1 AND condition2;
SELECT * FROM table_name WHERE condition1 OR condition2;
SELECT * FROM table_name WHERE NOT condition;
SELECT * FROM table_name WHERE condition1 AND (condition2 OR condition3);
SELECT * FROM table_name WHERE EXISTS (SELECT column_name FROM table_name WHERE condition);
SELECT * FROM table_name ORDER BY column;
SELECT * FROM table_name ORDER BY column DESC;
SELECT * FROM table_name ORDER BY column1 ASC, column2 DESC;
SELECT TOP: used to specify the number of records to return from top of table
SELECT TOP number columns_names FROM table_name WHERE condition;
SELECT TOP percent columns_names FROM table_name WHERE condition;
SELECT column_names FROM table_name LIMIT offset, count;
SELECT column_names FROM table_name WHERE column_name LIKE pattern;
LIKE ‘a%’
LIKE ‘%a’
LIKE ‘%or%’
LIKE ‘_r%’
LIKE ‘a_%_%’
LIKE ‘[a-c]%’