This site runs best with JavaScript enabled.Lesson 3: SELECT statement with specific columns.

Lesson 3: SELECT statement with specific columns.


Knowledge (of the fields) is Power

So we've seen that SELECT * returns all of the columns in our data table.

Handy Real-Life Hint: dont do this.

You can run into performance problems with this if you are hitting a big table or, worse, joining large tables together. Were running before we walk here so Ill advise being a bit more specific in your request.

Be laser focused.

You should know the different fields that sit in your database table so it pays to be a bit more strategic when picking which ones you actually need to pull back.

Lets say we are building a contact list and have all of our customer details in a table cunningly called CUSTOMERS.

If we want to get only the customers first name, date of birth and email address rather their full address and personal details we might do something like this:

SELECT firstname, dob, email
FROM Customers;

Little bit more typing but less data being brought back and you actually get what you want so its well worth it.

Now we know which fields we want to get back and where to get them from. This is now a valid SQL SELECT statement, well done. Stick "SQL Expert" on your CV and away you go.

Quiz Time.

The Question.

SELECT * brings back too much data. But what would we query for if we only wanted to return the name of our superheroes? Type your SQL statement in the editor below and hit the Run SQL button to see how you get on.

The Data.

The Editor.



The Answer.

Correct SQL:

Correct Output:

Share lesson