Sitemap
Elvan Tektaş

Elvan Tektaş

Full-Stack Developer - Computer Programming 👩‍💻 https://github.com/tektaselvan

SQL Or

Dec 4, 2023

--

The SQL OR Operator

Syntax

SELECT column1, column2, …
FROM table_name
WHERE condition1 OR condition2 OR condition3 …;

Example:

The OR operator is used to filter records based on more than one condition, like if you want to return all customers from Germany but also those from Spain:

Press enter or click to view image in full size
Or

OR vs AND

The OR operator displays a record if any of the conditions are TRUE.

Get Elvan Tektaş’s stories in your inbox

Join Medium for free to get updates from this writer.

The AND operator displays a record if all the conditions are TRUE.

At Least One Condition Must Be True

The following SQL statement selects all fields from Customers where either City is "London", CustomerName starts with the letter "E" or Country is "Norway":

Press enter or click to view image in full size

Combining AND and OR

You can combine the AND and OR operators.

The following SQL statement selects all customers from UKthat starts with a “E” or an “B”.

Make sure you use parenthesis to get the correct result.

Press enter or click to view image in full size

--

--

Elvan Tektaş
Elvan Tektaş

Written by Elvan Tektaş

Full-Stack Developer - Computer Programming 👩‍💻 https://github.com/tektaselvan