# SELECT: retrieve data
Run through and play with the interactive database for this lecture to learn about this better!
Just as we can insert data into a table, we can retrieve it. We saw some examples of how to do this in earlier chapters, but now we'll go into a bit more depth.
The SQL command for retrieving data is
SELECT. To use it, we must employ the appropriate keywords as well as give the database which columns we want to see in our result, as well as which table we want to get data from.
Something like this:
SELECT first_name, surname FROM users;
Would get all the data from the
users table, and show us the
surname columns in the result.
We can get a single column in the result:
SELECT first_name FROM users;
And also, we can tell the database we want all the columns in the table by using the asterisk (
*). This character means "all columns":
SELECT * FROM users;
As usual there are 3 parts to this query:
- Which columns you want to get back as a result:
- Where you want to get these columns from:
- The query-ending semicolon:
# How can I filter the data?
You'll have to use the
WHERE keyword. We're going to learn more about it in the next chapter!
# How can I select data from multiple tables?
You'll have to learn about and use
JOIN. This is a little bit more advanced, so we'll learn about it later on in the course. But rest assured, it can be done!