SQL Exercises: Select specified columns with where clause
From the following table, write a SQL query to locate salespeople who live in the city of 'Paris'. Return salesperson's name, city.
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 :
-- This query selects specific columns 'name' and 'city' from the 'salesman' table.
SELECT name, city
-- Specifies the table from which to retrieve the data (in this case, 'salesman').
FROM salesman
-- Filters the rows to only include those where the 'city' column has the value 'Paris'.
WHERE city = 'Paris';
Output of the Query:
name city Nail Knite Paris Mc Lyon Paris
Code Explanation:
The said query in SQL that selects "name" and "city" columns from the 'salesman' table where the value of "city" column is 'Paris'. The WHERE clause is used to filter the rows and only return the rows that match the condition specified in the WHERE clause.
As a result, all the rows from the 'salesman' table with a "city" column of 'Paris' will be returned, along with their "name" and "city" columns.

Visual presentation:

Practice Online
For more Practice: Solve these Related Problems:
- Write a SQL query to find customers who live in "London".
- Write a SQL query to locate employees working in the "New York" office.
- Write a SQL query to retrieve suppliers based in "Berlin".
- Write a SQL query to identify products manufactured in "Tokyo".
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous SQL Exercise: Identify distinct values in a table.
Next SQL Exercise: Select all columns that satisfy a specific condition.
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