Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to use DISTINCT in SQL

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-09-2009
Member
 
Join Date: Nov 2008
Posts: 1,185
How to use DISTINCT in SQL
  

I am in search of someone who can help me in my SQL query. I am having problem with my DISTINCT. My query is as below:

Code:
SELECT DISTINCT(empId) FROM (SELECT empId FROM Employee WHERE Name LIKE 'R%')
But the above query gives me the message as "Incorrect syntax near ')". Can anyone help me figure out how to use DISTINCT in SQL?

Reply With Quote
  #2  
Old 07-09-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: How to use DISTINCT in SQL

The SQL DISTINCT command retrieves only unique data entries depending on the column list you have specified after it. The SELECT statement provides us all the information from column(s) on a table. Situations may arise where you will be find a lot of duplicates in the result that you got. To remove all this duplicates, we need to use DISTINCT after SELECT keyword. The syntax is as follows:

Quote:
SELECT DISTINCT col_name
FROM table1
Reply With Quote
  #3  
Old 07-09-2009
Member
 
Join Date: Nov 2008
Posts: 1,192
Re: How to use DISTINCT in SQL

You can even do the same thing as in here:

Code:
SELECT DISTINCT empId FROM Employee WHERE Name LIKE 'R%'
In other words, you don't need to add a sub-query in your SELECT statement. You can directly specify the condition in your query.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use DISTINCT in SQL"
Thread Thread Starter Forum Replies Last Post
Cannot highlight distinct cells in different rows and column in a Pivot table ? Grayson Windows Software 3 27-11-2010 04:25 AM
Select unique values without using distinct Maya Angelou Software Development 6 17-05-2010 10:26 AM
SQL UNIQUE and DISTINCT Taarank Software Development 5 10-05-2010 10:40 PM
What is the difference between Distinct and DistinctRow? Orion lella Software Development 4 04-02-2010 12:29 AM
Distinct OR Group By sidkid Windows Software 3 03-09-2009 08:36 PM


All times are GMT +5.5. The time now is 02:59 PM.