What is this Site!!

All about Real time requirements in Orale Stay Tune!!
Showing posts with label Distinct n order by. Show all posts
Showing posts with label Distinct n order by. Show all posts

Friday, February 8, 2008

SQL Server


>>Previous>>


Using Distinct to Eliminate duplicate Information


One can eliminate duplicates using Distinct keyword in the SELECT clause

SELECT DISTINCT column_list FROM table_Name
Where search_condition

Example

SELECT DISTINCT city
FROM authors

OR

SELECT DISTINCT city, state
FROM authors



Using ORDER BY clause



ORDER BY clause is used in SELECT statement to sort data

SELECT column_name
From Table_List
[order by column_name[ASC|DES]]

Example

SELECT title_id, au_id
FROM titleauthor
ORDER BY title_id, au_id

  • Default Order is Ascending
  • Since sort order being used by SQL Server can make difference in the ORDER BY clause, one should check default sort order of SQL Server using sp_helpsort
  • ORDER BY clause can not be used on text or image columns


SQL Order of Logical Operations (each operates from left to right)

NOT
AND
OR


>>>Next>>>