The ORDER BY keyword is used to sort the result-set by a specified column.
The ORDER BY keyword sort the records in ascending order by default.
select * from [AdventureWorks2012].[Person].[Address] order by Desc
2. Distinct Keyword
In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table.
The DISTINCT keyword can be used to return only distinct (Not Duplicate) values.
3. Where Clause
Where clause used to filter records.
The WHERE clause is used to extract only those records that fulfill a specified criterion.
select columnname1, columnname2 from tablename where columnname operator (=, , Like) criterion.
4. AND and OR Operator.
The AND & OR operators are used to filter records based on more than one condition.
The AND operator displays a record if both the first condition AND the second condition is true.
The OR operator displays a record if either the first condition OR the second condition is true.
have a look on both queries.
first one gives the result set without AND operator.
second query gives the result set with and operator.
have a look on the result sets.
the first one gives all the result data where city is “Ottawa”.
and the second one gives the result data where city is “Ottawa” and PostalCode is “K4B 1S2”
we get the result because both conditions are true.
true in sense that there are records in Person.Address table which has both City named Ottawa and PostalCode K4B 1S2.
please have a look on the second query and look for the condition.
the second condition after and operator which is postalcode “K4B 1S1”
look for first result set of which has marks.
for second query, why we are not getting any result for second query
we are selecting result for addressId = ‘458’ and postalcode =’K4B 1S1′
but in table [Person].[Address] we do not have such record which satisfies these two criterion values.
look for the result set we are getting in the above image.
we used OR operator between AddressID and PostalCode.
so we get the result record where AddressId is “458” and PostalCode is “K4B 1S1”
for OR Operator query does not have to satisfy both criterion values.






