Results 1 to 3 of 3

Thread: How to use DISTINCT in SQL

  1. #1
    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?

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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:

    SELECT DISTINCT col_name
    FROM table1

  3. #3
    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.

Similar Threads

  1. Replies: 3
    Last Post: 27-11-2010, 05:25 AM
  2. Select unique values without using distinct
    By Maya Angelou in forum Software Development
    Replies: 6
    Last Post: 17-05-2010, 10:26 AM
  3. SQL UNIQUE and DISTINCT
    By Taarank in forum Software Development
    Replies: 5
    Last Post: 10-05-2010, 10:40 PM
  4. What is the difference between Distinct and DistinctRow?
    By Orion lella in forum Software Development
    Replies: 4
    Last Post: 04-02-2010, 01:29 AM
  5. Distinct OR Group By
    By sidkid in forum Windows Software
    Replies: 3
    Last Post: 03-09-2009, 08:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,646,179.15601 seconds with 17 queries