Recap

 

Recap


Statement

How to Use It

Other Details

SELECTSELECT Col1Col2, ...Provide the columns you want
FROMFROM TableProvide the table where the columns exist
LIMITLIMIT 10Limits based number of rows returned
ORDER BYORDER BY ColOrders table based on the column. Used with DESC.
WHEREWHERE Col > 5A conditional statement to filter your results
LIKEWHERE Col LIKE '%me%'Only pulls rows where column has 'me' within the text
INWHERE Col IN ('Y', 'N')A filter for only rows with column of 'Y' or 'N'
NOTWHERE Col NOT IN ('Y', 'N')NOT is frequently used with LIKE and IN
ANDWHERE Col1 > 5 AND Col2 < 3Filter rows where two or more conditions must be true
ORWHERE Col1 > 5 OR Col2 < 3Filter rows where at least one condition must be true
BETWEENWHERE Col BETWEEN 3 AND 5Often easier syntax than using an AND


Other Tips


Though SQL is not case sensitive (it doesn't care if you write your statements as all uppercase or lowercase), we discussed some best practices. The order of the key words does matter! Using what you know so far, you will want to write your statements as:


SELECT col1, col2 FROM table1 WHERE col3 > 5 AND col4 LIKE '%os%' ORDER BY col5 LIMIT 10;


Notice, you can retrieve different columns than those being used in the ORDER BY and WHERE statements. Assuming all of these column names existed in this way (col1col2col3col4col5) within a table called table1, this query would run just fine.


Comments

Popular posts from this blog

Entity Relationship Diagrams

Arithmetic Operators

NOT