Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MYSQL query to eliminate duplicates

0 views
Skip to first unread message

SteveW

unread,
May 2, 2007, 9:05:02 AM5/2/07
to
Sorry for wrong newsgroup but I always get a quick response from here.


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

Stefan Ascher

unread,
May 2, 2007, 9:50:04 AM5/2/07
to
In article <46388c7e$1...@newsgroups.borland.com>, SteveW says...

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

SELECT DISTINCT * FROM dont_know
--
stefan

Stefan Ascher

unread,
May 2, 2007, 9:51:49 AM5/2/07
to
In article <MPG.20a2b578...@newsgroups.borland.com>, Stefan
Ascher says...

> In article <46388c7e$1...@newsgroups.borland.com>, SteveW says...
>
> > I need to select all records from a table but exclude any duplicates.
>
> SELECT DISTINCT * FROM dont_know

No, this would probably return nothing, don't know, sorry.
--
stefan

Tom Wedge

unread,
May 2, 2007, 10:28:12 AM5/2/07
to
SteveW wrote:

Hi Steve

try

select min(q1."ticket No"), q1."Reg"
from Tickets q1
group by q1."Reg"

This should give you the grouping on the Reg field and will return the
lowest Ticket no value for the group value Reg.

Tom

--

Ray Marron

unread,
May 2, 2007, 10:37:28 AM5/2/07
to
"SteveW" <Steve...@btinternet.com> wrote in message
news:46388c7e$1...@newsgroups.borland.com...

> Sorry for wrong newsgroup but I always get a quick response from here.

This question was posted and answered in b.p.d.database.sqlservers.

You are aware of the posting guidelines and apologise *in advance* for your
misuse, yet still choose to ignore them for your own convenience. I doubt
your mother would approve of such behavior.

--
Ray Marron


Wilson

unread,
May 2, 2007, 11:13:00 AM5/2/07
to
> I doubt your mother would approve of such behavior.

What if she did...?


Allan Brocklehurst

unread,
May 2, 2007, 1:04:56 PM5/2/07
to SteveW
Try this

SELECT T1.Reg, T2.Reg, RECID
from Table1 T1, Table1 T2
where T1.RECID = T2.RECID
and T1.Reg <> T2.Reg;

Tony Caduto

unread,
May 2, 2007, 9:19:42 PM5/2/07
to
Well in PostgreSQL you would use Select DISTINCT. Probably the same for
MySQL.

--
Tony Caduto
AM Software Design
Home of Lightning Admin for PostgreSQL and MySQL
http://www.amsoftwaredesign.com

0 new messages