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

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-05-2010
Member
 
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.
Reply With Quote
  #2  
Old 09-05-2010
Member
 
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
Reply With Quote
  #3  
Old 09-05-2010
Member
 
Join Date: May 2008
Posts: 2,008
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)
Reply With Quote
  #4  
Old 09-05-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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)
Reply With Quote
  #5  
Old 09-05-2010
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
  #6  
Old 13-05-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Select unique records from a table"
Thread Thread Starter Forum Replies Last Post
Select unique values using xsl Elizabeth Allen Software Development 6 17-05-2010 10:27 AM
Select unique column in sql server Trini Alvarado Software Development 6 17-05-2010 10:24 AM
PHP mysql select unique records from one table Captain Carrot Software Development 6 13-05-2010 12:18 PM
Count unique records with sql kyosang Software Development 3 25-12-2009 12:45 PM
SELECT UNIQUE and SELECT DISTINCT TAARIQ Software Development 3 03-06-2009 10:00 PM


All times are GMT +5.5. The time now is 06:21 PM.