w3resource
SQL exercises

SQL VIEW Exercises: Create a view for all the salesmen with columns salesman_id, name and city

SQL VIEW: Exercise-2 with Solution

2. Write a query to create a view for all salesmen with columns salesman_id, name and city.

Sample table: salesman


Sample Solution:

CREATE VIEW salesown
 AS SELECT salesman_id, name, city
 FROM salesman;

Original salesown

Sample Output:

sqlpractice=# SELECT *
sqlpractice-# FROM salesown;
 salesman_id |     name     |   city
-------------+--------------+----------
        5002 | Nail Knite   | Paris
        5005 | Pit Alex     | London
        5006 | Mc Lyon      | Paris
        5003 | Lauson Hense |
        5007 | Paul Adam    | Rome
        5001 | James Hoog   | New York
(6 rows)

Now UPDATE the city name which salesman_id is '5007'.

Code

UPDATE salesown
SET city = 'London'
WHERE salesman_id = 5007;

output

sqlpractice=# SELECT *
sqlpractice-# FROM salesown;
 salesman_id |     name     |   city
-------------+--------------+----------
        5002 | Nail Knite   | Paris
        5005 | Pit Alex     | London
        5006 | Mc Lyon      | Paris
        5003 | Lauson Hense |
        5001 | James Hoog   | New York
        5007 | Paul Adam    | London
(6 rows)

Inventory database model:

Inventory database model

Contribute your code and comments through Disqus.

Previous: Write a query to create a view for those salesmen belongs to the city New York.
Next: Write a query to find the salesmen of the city New York who achieved the commission more than 13%.

What is the difficulty level of this exercise?



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