Click to See Complete Forum and Search --> : [RESOLVED] No duplicates ...
Avihai
01-17-2008, 06:54 AM
Hi all,
I have a query that pulls names from the db. It just might be possible that a certain name would appear twice.
This is the SQL:
SELECT name FROM table WHERE section=4 AND ORDER by name ASC
How can I say: pull a duplicated name only once, the first entry?
I am using php for coding.
Thanks,
Avihai
cs3mw
01-17-2008, 07:43 AM
This hasnt been tested so let me know but it think you need the following:
SELECT DISTINCT name FROM table WHERE section=4 AND ORDER by name ASC
Avihai
01-17-2008, 08:10 AM
This hasnt been tested so let me know but it think you need the following:
SELECT DISTINCT name FROM table WHERE section=4 AND ORDER by name ASC
Thanks :-)
I have tried:
SELECT name FROM table WHERE section=4 AND GROUP by name ORDER by name ASC
and it worked ... why?
cs3mw
01-17-2008, 08:47 AM
have you copied and pasted the wrong code above because that was your original code. If the code I recommended worked then its because of the use of DISTINCT. What that does is tells the mysql engine to return distinct values i.e. if a copy is repeated then it doesnt give repeated values.
A good example of this would be a table of school children which also includes what teacher teaches them. And from that table a query could be created to see list all teachers within that school.
Hope this helps
Mike
Avihai
01-17-2008, 09:41 AM
Thanks a lot :-)