Simple SELECTs

SELECTs are the simplest and most commonly used SQL statement. You use them to get data out of tables in your database.

Here's a simple example:

SELECT manufacturer FROM cars

This gets the manufacturer for each car in the cars table. You might expect an answer like this:

You can SELECT more than one thing at a time:

SELECT manufacturer, model FROM cars

So what's actually going on here? cars is a table full of data about cars, and manufacturer and model are the names of two of its columns. SELECT manufacturer, model FROM cars means "go and get the manufacturer and model for every car in the cars table".

You can select as many columns as you like. Just separate each column name with a comma.

To give you some practice at writing your own SELECT statements, we've written some tasks for you to complete. Each task asks you to pull some data out of a database by writing a SQL query. Once you've typed in the query and hit Run it, the Result column displays the result of the query, and whether it's the right answer or not. If you've got the right answer, then you can try another task.

If you feel like you've got the hang of the current lesson, you can move onto the next lesson by hitting Next lesson at the bottom of the page.

Task

What your results should look like

Query

Result

There was an error in your SQL query: {{error}}

{{executedQuery}}

Correct answer. Bonza!

Congratulations! You've completed all of the tasks in this lesson.

Next lesson: SELECT *

Wrong answer. Have another a go.

Hint: {{hint}}

Next lesson: SELECT *

Once you think you've nailed this lesson, feel free to go to the next lesson.

Next lesson

Questions? Suggestions?

We'd love to hear any feedback you have for us. Just send an email to hello@learnsomesql.com.