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

book
SQL And, Or, Not

To combine multiple conditions, use AND, OR, and NOT keywords, and also brackets (, ) to set the priority.

For example, you want to select all songs' titles, that were produced between 1970 and 1990 years:

SELECT title FROM songs
WHERE year >= 1970 AND year <= 1990
12
SELECT title FROM songs WHERE year >= 1970 AND year <= 1990
copy

Or you can select all records where singer is not Pink Floyd:

SELECT * FROM songs
WHERE NOT singer = 'Pink Floyd'
12
SELECT * FROM songs WHERE NOT singer = 'Pink Floyd'
copy

You can combine conditions for different columns, but not forget about brackets to define the priority:

SELECT * FROM songs
WHERE NOT (singer = 'Pink Floyd' AND price = 100)
12
SELECT * FROM songs WHERE NOT (singer = 'Pink Floyd' AND price = 100)
copy
Task

Swipe to start coding

Find all songs titles and prices of 20th century, where the price is less than 500, or where the singer is AC/DC.

Solution

SELECT title, price FROM songs
WHERE year <= 2000 AND (price < 500 OR singer = 'AC/DC')

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 7
single

single


Query ResultQuery Result
No query executed yet...

Ask AI

expand

Ask AI

ChatGPT

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

some-alt