SQL Exercises: Filter records using where clause and or operator
From the following table, write a SQL query to find the details of those salespeople who come from the 'Paris' City or 'Rome' City. Return salesman_id, name, city, commission.
Sample table: salesman
salesman_id | name | city | commission -------------+------------+----------+------------ 5001 | James Hoog | New York | 0.15 5002 | Nail Knite | Paris | 0.13 5005 | Pit Alex | London | 0.11 5006 | Mc Lyon | Paris | 0.14 5007 | Paul Adam | Rome | 0.13 5003 | Lauson Hen | San Jose | 0.12
Sample Solution:
Output of the Query:
salesman_id name city commission 5002 Nail Knite Paris 0.13 5006 Mc Lyon Paris 0.14 5007 Paul Adam Rome 0.13
Code Explanation:
The said SQL query that selects all columns (*) from the table called 'salesman' where the city is either 'Paris' or 'Rome'. It will return all rows from the 'salesman' table where the city column has a value of 'Paris' or 'Rome'.
Relational Algebra Expression:

Relational Algebra Tree:

Explanation:
Visual presentation :
Practice Online
For more Practice: Solve these Related Problems:
- Write a SQL query to find the details of salespeople who come from either 'London' or 'New York'. Return salesman_id, name, city, commission.
- Write a SQL query to retrieve the details of salespeople whose city is not 'Paris'. Return salesman_id, name, city, commission.
- Write a SQL query to find the details of salespeople who belong to cities starting with the letter 'P'. Return salesman_id, name, city, commission.
- Write a SQL query to list all salespeople except those who live in 'Rome'. Return salesman_id, name, city, commission.
Contribute your code and comments through Disqus.
Previous SQL Exercise: SQL Wildcard and Special operators Exercises Home
Next SQL Exercise: Filter records using in operator.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics