Dynadot โ€” .com Transfer

Selecting Just 1 Of Duplicates

Spaceship Spaceship
Watch

boomers

Established Member
Impact
4
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
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Group by will work for you :D

Code:
SELECT * FROM (TABLE) GROUP BY names
 
0
•••
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.
 
0
•••
Select help from google where searchterm = sql
 
0
•••
That's helpful. Arrogant people like you are the problem with forums like this.
 
1
•••
That's helpful. Arrogant people like you are the problem with forums like this.

Actually I was just trying to be cute. If the answer had not already been stated then I would have provided it to you. I'm actually not a jerk.

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!
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back