Results 1 to 6 of 6

Thread: Select unique records from a table

  1. #1
    Join Date
    Dec 2009
    Posts
    40

    Select unique records from a table

    Hello to all,
    I have table like "User". Below is the structure and data of it.
    Code Name EFFECTIVE_DATE (dd/mm/yyyy)
    =====================
    s1 Tom 1/5/2005
    s2 Alexa 1/6/2005
    s2 Alexa 15/6/2005

    I want query that produces the following output

    Code Name EFFECTIVE_DATE (dd/mm/yyyy)
    =====================
    s1 Tom 1/5/2005
    s2 Alexa 15/6/2005
    Can anyone tell me how to select unique records from a table? Please help me.
    Thank you.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Select unique records from a table

    Hey you have to write following Sql query to get unique record from the table. It is very simple to use. In the following code DISTINCT clause is used to get unique record from the specifying table. In the following code I use FROM clause to get data from the table name "user".
    Code:
    SELECT DISTINCT Name FROM user

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Select unique records from a table

    If you want to copy distinct records from one table to another then you have to use following code. In the following code I have use DISTINCT clause to remove duplicate record from the table and gives you single unique record. Just try to understand it.
    Code:
     INSERT INTO tables1 VALUES (SELECT DISTINCT x,y,z.. FROM user)

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Select unique records from a table

    Hey why don't you remove duplicate record from your table. I have written following SQL for you. Just try to understand it. I have written one of the example of it. In the following code I have use GROUP BY clause.
    Code:
     
    SELECT * FROM emps as
    WHERE rowids = (SELECT maxs(rowids) FROM emps
    WHERE empnos = as.empnos
    GROUP BY empnos
    HAVING count(*) >1)

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Select unique records from a table

    As per my information you have to use GROUP BY clause to get rid out of this problem. I have given one example of GROUP BY clause. Just try to understand each steps.
    Code:
    select ids, term from project_term WHERE pids='$_SESSION[project_ids]' GROUP BY terms
    This GROUP BY clause is used to group all the terms which are same.

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Select unique records from a table

    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 (different) values.
    SQL SELECT DISTINCT Syntax
    SELECT DISTINCT column_name(s)
    FROM table_name

Similar Threads

  1. Select unique values using xsl
    By Elizabeth Allen in forum Software Development
    Replies: 6
    Last Post: 17-05-2010, 10:27 AM
  2. Select unique column in sql server
    By Trini Alvarado in forum Software Development
    Replies: 6
    Last Post: 17-05-2010, 10:24 AM
  3. PHP mysql select unique records from one table
    By Captain Carrot in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 12:18 PM
  4. Count unique records with sql
    By kyosang in forum Software Development
    Replies: 3
    Last Post: 25-12-2009, 12:45 PM
  5. SELECT UNIQUE and SELECT DISTINCT
    By TAARIQ in forum Software Development
    Replies: 3
    Last Post: 03-06-2009, 10:00 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,714,139,362.86420 seconds with 17 queries