Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn SQL Where | Database & Introduction to Syntax
SQL Tutorial for Beginners

book
SQL Where

You’ll need to filter your selected data very often, so you need to use WHERE keyword. After WHERE you put some condition or combination of them. Usually it is some column's values limitations.

For example, you want to select records where singer is AC/DC:

SELECT * FROM songs
WHERE singer = 'AC/DC'
12
SELECT * FROM songs WHERE singer = 'AC/DC'
copy

Another example of the query using the WHERE statement. It retrieves all records with a price column value greater than 100. The syntax is pretty easy to understand: WHERE price > 100.

SELECT * FROM songs
WHERE price > 100
12
SELECT * FROM songs WHERE price > 100
copy

Here you can see the main syntax.

  • Use = to find fields which values are equal to some naming.

  • Use != or <> to find non-equal fields.

  • Use >, <, >=, <= for comparing.

  • Use single quotes 'Quotes' for string values.

  • Use () brackets for prioritization.

/* all records where year column is greater or equal than 1970*/
SELECT * FROM songs
WHERE year >= 1970
123
/* all records where year column is greater or equal than 1970*/ SELECT * FROM songs WHERE year >= 1970
copy

For string values, you have to write them inside single quotes. Like 'ABBA', 'Toxic' etc. Check carefully string values in the condition statements: no extra spaces, correct capitalization (for example, Britney Spears is correct, not BRITNEY SPEARS or britney spears). Otherwise, you'll receive the Internal Server Error.

Task

Swipe to start coding

Select all records with Britney Spears as a singer. Change your query to select only Britney Spears songs' titles (not full records, only column title).

Solution

select title from songs
where singer = 'Britney Spears'

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 5

Query ResultQuery Result
No query executed yet...

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

We use cookies to make your experience better!
some-alt