SQL VIEW Exercises: Create a view to find the salesmen of the city New York

SQL VIEW : Exercise-3 with Solution

3. From the following table, create a view to find the salespersons of the city 'New York'.

Sample table: salesman

Sample Solution:

Code to create the view

CREATE VIEW newyorkstaff
FROM salesman
WHERE city = 'New York';

Code to see the records form the view

FROM newyorkstaff
WHERE commission > .13;


sqlpractice=# SELECT *
sqlpractice-# FROM newyorkstaff
sqlpractice-# WHERE commission > .13;
 salesman_id | name       |   city   | commission
        5001 | James Hoog | New York |       0.15
(1 row)

Inventory database model:

Inventory database model

Contribute your code and comments through Disqus.

Previous: From the following table, create a view for all salespersons. Return salesperson ID, name, and city.
Next: From the following table, create a view to count the number of customers in each grade.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?

Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

How to insert a line break in a SQL Server VARCHAR/NVARCHAR string?

SET @text = 'This is line 1.' + CHAR(13) + 'This is line 2.'
SELECT @text

This prints out the following:

This is line 1.

This is line 2.

Database: SQL Server

Ref: https://bit.ly/3ry1pBI