w3resource
SQL exercises

SQL VIEW Exercises: Create a view that shows the salesmen who issued orders on October 10th, 2012

SQL VIEW: Exercise-15 with Solution

15. Write a query to create a view that finds the salesmen who issued orders on October 10th, 2012.

Sample table: salesman


Sample table: orders


Sample Solution:

CREATE VIEW salesmanonoct
AS SELECT *
FROM salesman
WHERE salesman_id IN
    (SELECT salesman_id
         FROM orders
         WHERE ord_date = '2012-10-10');

output:

sqlpractice=# SELECT *
sqlpractice-# FROM salesmanonoct;
 salesman_id |     name     | city  | commission
-------------+--------------+-------+------------
        5006 | Mc Lyon      | Paris |       0.14
        5003 | Lauson Hense |       |       0.12
(2 rows)

Inventory database model:

Inventory database model

Contribute your code and comments through Disqus.

Previous: Write a query to create a view that shows the number of orders in each day.
Next: Write a query to create a view that find the salesmen who issued orders on either August 17th, 2012 or October 10th, 2012.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming