?

How to write SQL - Quick Help

Check out these instructions for how to write your first SQL statements. Or check out our videos on how to write SQL.

Sample Questions

Don't know what questions to ask of the data? Try these sample questions to get you started:

The Clauses

SELECT [fields/aggregations]: These are the fields and/or aggregations. Just write them out with a comma between each one.

EXAMPLE: SELECT gender,AVG(height)


FROM [table]: This is the table you'll be querying. Just write the name of the table you're interested in. Check out the Tables tab to see what options you have. You can upload your own CSV file as a table!

EXAMPLE: FROM students


WHERE [condition]: This is something to check for on every row of your table. If the condition is false, then we will filter out those rows. Check values of a field against a number or another field with: >, <, =, >=, <=, or !=. Don't forget to put strings in "quotes", or else SQL will think it's the name of a field.

EXAMPLE: WHERE name != "Emma"

EXAMPLE: WHERE age >= 20


GROUP BY [fields]: This is a list of fields that we want to know something about. SQL will give you the unique combinations of these values in your final result. Be sure to SELECT the groups to see the unique values, and pair this with some aggregates in your SELECT statement to get information about those groups!

EXAMPLE:GROUP BY gender


HAVING [condition]: Much like the WHERE clause, the having will filter out rows, but only AFTER the GROUP BY clause. You can only put HAVING conditions on aggregates!

EXAMPLE:HAVING count(*) > 1


ORDER BY [fields/aggregates]: Your query is all done, but we can finally see the information more clearly by ordering the results in a specific way. Just list out the fields you want to sort the final result by (in order of importance). You can even put "desc" if you want to go top to bottom instead of bottom up.

EXAMPLE: ORDER BY AVG(height) desc, gender


Auto-Play:

Speed: