Lesson 3: SELECT statement with specific columns.

By Alan Hylands — 2 minute read

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: don’t do this.

You can run into performance problems with this if you are hitting a big table or, worse, joining large tables together. We’re running before we walk here so I’ll 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.

Let’s 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 customer’s 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 it’s 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.


Show Answer

The Answer.

Correct SQL:

                    SELECT name FROM characters;

Correct Output:

Try the next lesson