
SQL UNION Exercises: Create a union of two queries that shows the names, cities, and ratings of all customers with a comment string
SQL UNION : Exercise-8 with Solution
8. Write a query to create a union of two queries that shows the names, cities, and ratings of all customers. Those with a rating of 300 or greater will also have the words High Rating, while the others will have the words Low Rating.
Sample table: Customer
Sample Solution:
SELECT customer_id, city, grade, 'High Rating'
FROM customer
WHERE grade >= 300
UNION
(SELECT customer_id, city, grade, 'Low Rating'
FROM customer
WHERE grade < 300)
Sample Output:
customer_id city grade ?column? 3002 New York 100 Low Rating 3003 Moscow 200 Low Rating 3004 Paris 300 High Rating 3008 London 300 High Rating 3005 California 200 Low Rating 3007 New York 200 Low Rating 3009 Berlin 100 Low Rating
Practice Online

Query Visualization:
Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a query to that appends strings to the selected fields, indicating whether or not a specified salesman was matched to a customer in his city.
Next: Write a query that produces the name and number of each salesman and each customer with more than one current order. Put the results in alphabetical order.
What is the difficulty level of this exercise?
New Content: Composer: Dependency manager for PHP, R Programming