SELECT with WHERE and ORDER BY



By:

Overview
Let's bring the WHERE and ORDER BY concepts together in this tutorial.

Explanation
In the example below we are selecting the LoginID column from the HumanResources.Employee table where the VacationHours column equals 8 and we are ordering the data by the HireDate in ascending order which is implied.

USE AdventureWorks;
GO 
SELECT LoginID
FROM HumanResources.Employee
WHERE VacationHours = 8
ORDER BY HireDate;
GO

Below is the sample result set:


Last Update: 3/9/2009






Comments For This Article




Monday, January 14, 2019 - 12:39:24 PM - Thunder Back To Top (78764)

hi,Can i use (https://www.mssqltips.com/sqlservertutorial/11/select-with-where-and-order-by/) this query code without "go" ?

As (SELECT * FROM posts ORDER BY time ASC LIMIT 8 OFFSET 0 WHERE category_id=4).

Thanks a lot for Answer!



download














get free sql tips
agree to terms