SELECT SQL Syntax

Written by SQL

SELECT Syntax

SyntaxAction
SELECT [col] FROM [table]Selects a column from the specified table.
SELECT [col1], [col2] FROM [table]Selects 2 columns from the specified table
SELECT * from [table]Selects all columns from the specified table
SELECT DISTINCT [col] FROM [table]Selects unique values from the specified column and table
SELECT COUNT(DISTINCT [col]) FROM [table]Returns the number of rows that match specified constraints
Select Syntax Cheat Sheet

WHERE Syntax

SyntaxAction
SELECT [col] FROM [table] WHERE [condition]Selects records that meets the specified condition
. . . WHERE [col]=[record]Where a column matches matches a record
. . . WHERE [col]=[keyword]Where a column matches a keyword
. . . WHERE [col]=[integer]Where an column is a specified integer
Where Syntax Cheat Sheet

AND Syntax

SyntaxAction
SELECT [col] FROM [table] WHERE [condition1] AND [condition2]Selects records when both conditions are met
. . . WHERE [col]=[record] AND [col]=[record]Selects records when both conditions are met
. . . WHERE [col]=[record] AND ([col]=[record] OR [coll]=[record])Selects records when one of the conditions is met
. . . WHERE NOT [col]=[record] AND NOT [col]=[record]Selects records that meet neither condition
AND Syntax Cheat Sheet

ORDER BY Syntax

SyntaxAction
SELECT [col] FROM [table] ORDER BY [condition]Returns records ordered by condition
. . . ORDER BY [col] DESCReturns records in descending order
. . . ORDER BY [col1], [col2]Returns records in ascending order from col1. Any matching records, will be ordered based on col2
. . . ORDER BY [col], [col2] DESCReturns col1 in ascending order while duplicates are returned in descending order determined by col2.
ORDER BY Syntax Cheat Sheet

Talk soon,
Shane Bellone