w3resource

AdventureWorks Database: Fetch first twenty rows from the table

SQL Query - AdventureWorks: Exercise-50 with Solution

50. From the following table write a query in SQL to fetch first twenty rows. Return jobtitle, hiredate. Order the result set on hiredate column in descending order.

Sample table: HumanResources.Employee


Click to view Full table

Sample Solution:

SELECT JobTitle, HireDate  
FROM HumanResources.Employee
ORDER BY HireDate desc
FETCH FIRST 20 ROWS ONLY;

Sample Output:

jobtitle               |hiredate  |
-----------------------+----------+
Sales Representative   |2013-05-30|
Sales Representative   |2013-05-30|
Pacific Sales Manager  |2013-03-14|
Sales Representative   |2012-09-30|
Sales Representative   |2012-05-30|
Sales Representative   |2012-05-30|
European Sales Manager |2012-04-16|
Sales Representative   |2011-05-31|
Sales Representative   |2011-05-31|
Sales Representative   |2011-05-31|
Sales Representative   |2011-05-31|
Sales Representative   |2011-05-31|
Sales Representative   |2011-05-31|
...

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Address for city outside US starts with Pa.
Next: Orders with orderqtys, unitpricediscount, totaldues.

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