AdventureWorks Database: Retrieve only the rows for product

SQL Query - AdventureWorks: Exercise-4 with Solution

4. From the following table write a query in SQL to return only the rows for product that have a sellstartdate that is not NULL and a productline of 'T'. Return productid, productnumber, and name. Arranged the output in ascending order on name.

Sample table: production.product

Click to view Full table

Sample Solution:

SELECT productid, productnumber, name as producName
FROM production.product
WHERE sellstartdate IS NOT NULL
AND production.product.productline= 'T'
ORDER BY name;

Sample Output:

productid|productnumber|producname                   |
      890|FR-T98U-46   |HL Touring Frame - Blue, 46  |
      891|FR-T98U-50   |HL Touring Frame - Blue, 50  |
      892|FR-T98U-54   |HL Touring Frame - Blue, 54  |
      893|FR-T98U-60   |HL Touring Frame - Blue, 60  |
      887|FR-T98Y-46   |HL Touring Frame - Yellow, 46|
      888|FR-T98Y-50   |HL Touring Frame - Yellow, 50|
      889|FR-T98Y-54   |HL Touring Frame - Yellow, 54|
      885|FR-T98Y-60   |HL Touring Frame - Yellow, 60|
      947|HB-T928      |HL Touring Handlebars        |
      916|SE-T924      |HL Touring Seat/Saddle       |
      903|FR-T67U-44   |LL Touring Frame - Blue, 44  |
      895|FR-T67U-50   |LL Touring Frame - Blue, 50  |
      896|FR-T67U-54   |LL Touring Frame - Blue, 54  |
      897|FR-T67U-58   |LL Touring Frame - Blue, 58  |

SQL AdventureWorks Editor:

Practice Online

Contribute your code and comments through Disqus.

Previous: Returns all rows and a subset of the columns.
Next: Calculate the percentage of tax on subtotal.

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