AdventureWorks Database: Fetch result set on an unspecified column

SQL Query - AdventureWorks: Exercise-29 with Solution

29. Write a query in SQL to fetch rows from product table and order the result set on an unspecified column listprice. Return product ID, name, and color of the product.

Sample table: Production.Product

Click to view Full table

Sample Solution:

SELECT ProductID, Name, Color  
FROM Production.Product  
ORDER BY ListPrice;

Sample Output:

productid|name                            |color       |
      388|Hex Nut 11                      |            |
        2|Bearing Ball                    |            |
        3|BB Ball Bearing                 |            |
        4|Headset Ball Bearings           |            |
      316|Blade                           |            |
      317|LL Crankarm                     |Black       |
      318|ML Crankarm                     |Black       |
      319|HL Crankarm                     |Black       |
      320|Chainring Bolts                 |Silver      |
      321|Chainring Nut                   |Silver      |
      322|Chainring                       |Black       |
      323|Crown Race                      |            |
      324|Chain Stays                     |            |
      325|Decal 1                         |            |
      326|Decal 2                         |            |
      327|Down Tube                       |            |
      328|Mountain End Caps               |            |

SQL AdventureWorks Editor:

Practice Online

Contribute your code and comments through Disqus.

Previous: Products whose names start with Lock Washer.
Next: Records of employees, order on hiredate.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

T-SQL Cast versus Convert?

CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

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