| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Jun 2005
Posts: 518
![]() ![]() | Selecting Just 1 Of Duplicates I've an SQL select statement that I use to display some records within a DataList. Within my database there are duplicate records (not in error, they are supposed to be there), but instead of these duplicates showing in the Datalist for every record; I want just one to be shown. Records in database: ID Names 1 John 2 Sean 3 Michael 4 John 5 William Required selected: John ????: NamePros.com http://www.namepros.com/programming/676787-selecting-just-1-of-duplicates.html Sean Michael William Does anyone know who to achieve this? ---------- Post added at 11:18 PM ---------- Previous post was at 10:06 PM ---------- I've found the 'distinct' statement but cant get it to only use one column for the duplicates... Records in database: ID Names 1 John 18 2 Sean 18 3 Michael 19 4 John 18 5 William 21 Required selected: John 18 Sean 18 Michael 19 William 21
__________________ Free Horse Racing Tips |
| | |
| | #3 (permalink) |
| NamePros Member Join Date: Nov 2003 Location: Ontario, Canada
Posts: 127
![]() ![]() | To use distinct you need to have exactly the same info returned. When you do a select *, it is including you id. If you just wrote: select distinct Names from table; that would return what you are looking for. |
| | |
| | #6 (permalink) | ||||
| Senior Member Join Date: May 2009 Location: internet@ctivist.com
Posts: 4,790
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
????: NamePros.com http://www.namepros.com/showthread.php?t=676787 The GROUP BY will work just fine - the DISTINCT won't work as you found out. A distinct is just a specialized form of group (done by all selected columns) - I find this just confuses people. I'm not sure why you think there's a problem with forums like this. You posted your question - you got an answer. Sounds like it is working fairly well to me. I apologize for offending you. Please lighten up!
__________________ A Member of: IdeationTeam.com HowToBeADomainer.com - a Domaining How To AuthorEditor.com | ||||
| | |