w3resource

AdventureWorks Database: List all the products that are red or blue

SQL Query - AdventureWorks: Exercise-37 with Solution

37. From the following table write a query in SQL to list all the products that are Red or Blue in color. Return name, color and listprice.Sorts this result by the column listprice.

Sample table: Production.Product


Click to view Full table

Sample Solution:

SELECT Name, Color, ListPrice  
FROM Production.Product  
WHERE Color = 'Red'  
UNION ALL  
SELECT Name, Color, ListPrice  
FROM Production.Product  
WHERE Color = 'Blue'  
ORDER BY ListPrice ASC;

Sample Output:

name                       |color|listprice|
---------------------------+-----+---------+
Sport-100 Helmet, Blue     |Blue |    34.99|
Sport-100 Helmet, Red      |Red  |    34.99|
Classic Vest, S            |Blue |     63.5|
Classic Vest, L            |Blue |     63.5|
Classic Vest, M            |Blue |     63.5|
LL Touring Frame - Blue, 54|Blue |   333.42|
LL Touring Frame - Blue, 50|Blue |   333.42|
LL Touring Frame - Blue, 44|Blue |   333.42|
LL Touring Frame - Blue, 62|Blue |   333.42|
LL Touring Frame - Blue, 58|Blue |   333.42|
LL Road Frame - Red, 58    |Red  |   337.22|
LL Road Frame - Red, 60    |Red  |   337.22|
LL Road Frame - Red, 62    |Red  |   337.22|
LL Road Frame - Red, 44    |Red  |   337.22|
LL Road Frame - Red, 48    |Red  |   337.22|
...

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Fetch rows from the middle of a sorted table.
Next: Retrieve name and associated salesorders.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.

SQL: Tips of the Day

What's the difference between VARCHAR and CHAR?

VARCHAR is variable-length.

CHAR is fixed length.

If your content is a fixed size, you'll get better performance with CHAR.

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

 





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook