BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MYSQL query to eliminate duplicates

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
SteveW
Guest





PostPosted: Wed May 02, 2007 5:12 pm    Post subject: MYSQL query to eliminate duplicates Reply with quote



I need to select all records from a table but exclude any duplicates.

eg Table Tickets Field "reg" contains:

ticket No Reg
1 xy123
2 xy123
3 ab123
4 bc123
5 bc123

I need to return

ticket No Reg
1 xy123
3 ab123
4 bc123

Cheers

SteveW
Back to top
Vassiliev V. V.
Guest





PostPosted: Wed May 02, 2007 6:36 pm    Post subject: Re: MYSQL query to eliminate duplicates Reply with quote



In your example you have no duplicates in ticketNo column. For what you need

select min(ticketNo) as ticketNo, Reg
from Tickets
group by Reg

should work for most DBMS. To get only Reg

select distinct Reg from Tickets

should work.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"SteveW" <Stevewarby (AT) btinternet (DOT) com> сообщил/сообщила в новостях следующее:
news:46388039 (AT) newsgroups (DOT) borland.com...
Quote:
I need to select all records from a table but exclude any duplicates.

eg Table Tickets Field "reg" contains:

ticket No Reg
1 xy123
2 xy123
3 ab123
4 bc123
5 bc123

I need to return

ticket No Reg
1 xy123
3 ab123
4 bc123

Cheers

SteveW
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.