## SQL Query - AdventureWorks: Exercise-28 with Solution

28. From the following table write a query in SQL to retrieve products whose names start with 'Lock Washer'. Return product ID, and name and order the result set in ascending order on product ID column.

Sample table: Production.Product

Click to view Full table

Sample Solution:

``````SELECT ProductID, Name
FROM Production.Product
WHERE Name LIKE 'Lock Washer%'
ORDER BY ProductID;
``````

Sample Output:

```productid|name          |
---------+--------------+
463|Lock Washer 4 |
464|Lock Washer 5 |
465|Lock Washer 10|
466|Lock Washer 6 |
467|Lock Washer 13|
468|Lock Washer 8 |
469|Lock Washer 1 |
470|Lock Washer 7 |
471|Lock Washer 12|
472|Lock Washer 2 |
473|Lock Washer 9 |
474|Lock Washer 3 |
475|Lock Washer 11|
```

## Practice Online

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## SQL: Tips of the Day

How to request a random row in SQL?

Select a random row with MySQL:

```SELECT column FROM table
ORDER BY RAND()
LIMIT 1
```

Select a random row with PostgreSQL:

```SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
```

Select a random row with Microsoft SQL Server:

```SELECT TOP 1 column FROM table
ORDER BY NEWID()
```

Select a random row with IBM DB2:

```SELECT column, RAND() as IDX
FROM table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY
```

Select a random record with Oracle:

```SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1
```

Database: SQL Server, PostgreSQL Server, MySQL

Ref: https://bit.ly/39n35HP

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