For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > August 2004 > selecting only 1 of several duplicate records









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author selecting only 1 of several duplicate records
fozie

2004-08-18, 3:57 pm

say i have a statement as such :

select Name, ID from Staff where Status=1


However staff table contains duplicate entries of every record.
Is there a shortcut such that i only retrieve one of each duplicate
record, but all the unique records are retrieved

i.e there is more than 1 unique record where Status =1

i.e

ID Name Status
01 John 1
01 John 1
03 Tom 1
03 Tom 1
05 Sam 1
05 Sam 1
07 Chris 0
07 Chris 0

i want to retrieve one entry of each unique name



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


tox_yray

2004-08-18, 3:57 pm

I don,t think you can etrive only one, but you can SHOW only one:

1 - Sort them by ID in your query

2 - Declare id1="" before your loop

3-
id2=myresult['id'];

while (id1 != id2){

===yourscript here===

id1=id2
}

should work...



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com