Sort and remove duplicates

J

JimJx

Hi everyone,

Got what should be an easy problem.

I have a db (MySQL) that I need to sort on the first field and remove
dups from.

For example, let's say I have Red,1,2,3,4,5 and Blue,1,2,3,4,5 and
Green,1,2,3,4,5 and Green,2,2,2,2,2

How can I come out with Blue,1,2,3,4,5;Green,1,2,3,4,5;Red,1,2,3,4,5??

I know that there is a simple way to do this but my brain is not
functioning right now.

Thanks!
Jim
 
G

Greg Bacon

: I have a db (MySQL) that I need to sort on the first field and
: remove dups from.
:
: For example, let's say I have Red,1,2,3,4,5 and Blue,1,2,3,4,5
: and Green,1,2,3,4,5 and Green,2,2,2,2,2
:
: How can I come out with Blue,1,2,3,4,5;Green,1,2,3,4,5;
: Red,1,2,3,4,5??

Why does the Green row get 1,2,3,4,5 on the output?

Greg
 
J

JimJx

: I have a db (MySQL) that I need to sort on the first field and
: remove dups from.
:
: For example, let's say I have Red,1,2,3,4,5 and Blue,1,2,3,4,5
: and Green,1,2,3,4,5 and Green,2,2,2,2,2
:
: How can I come out with Blue,1,2,3,4,5;Green,1,2,3,4,5;
: Red,1,2,3,4,5??

Why does the Green row get 1,2,3,4,5 on the output?

Greg

Because Green would be a dup and 1,2,3,4,5 comes before 2,2,3,4,5
 
B

Ben Morrow

Quoth JimJx said:
Hi everyone,

Got what should be an easy problem.

I have a db (MySQL) that I need to sort on the first field and remove
dups from.

For example, let's say I have Red,1,2,3,4,5 and Blue,1,2,3,4,5 and
Green,1,2,3,4,5 and Green,2,2,2,2,2

How can I come out with Blue,1,2,3,4,5;Green,1,2,3,4,5;Red,1,2,3,4,5??

I know that there is a simple way to do this but my brain is not
functioning right now.

perldoc DBI
perldoc -q duplicate
(possibly perldoc -f sort as well)

When you've had a go, post your code and we'll help you fix it.

Ben
 
G

Greg Bacon

: On Sep 28, 10:33 am, (e-mail address removed) (Greg Bacon) wrote:
:
: > Why does the Green row get 1,2,3,4,5 on the output?
:
: Because Green would be a dup and 1,2,3,4,5 comes before 2,2,3,4,5

Ah. I thought you wanted to remove duplicates in the other columns
too. (The five 2s threw me off.)

Glenn Jackman's answer is what you want.

Greg
 
M

Martijn Lievaart

Hi everyone,

Got what should be an easy problem.

I have a db (MySQL) that I need to sort on the first field and remove
dups from.

For example, let's say I have Red,1,2,3,4,5 and Blue,1,2,3,4,5 and
Green,1,2,3,4,5 and Green,2,2,2,2,2

How can I come out with Blue,1,2,3,4,5;Green,1,2,3,4,5;Red,1,2,3,4,5??

I know that there is a simple way to do this but my brain is not
functioning right now.

select field1, min(field2), min(field3) ... from table group by field1;

HTH,
M4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top