Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Sort and remove duplicates

Reply
Thread Tools

Sort and remove duplicates

 
 
JimJx
Guest
Posts: n/a
 
      09-28-2007
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

 
Reply With Quote
 
 
 
 
Greg Bacon
Guest
Posts: n/a
 
      09-28-2007
In article <(E-Mail Removed). com>,
JimJx <(E-Mail Removed)> wrote:

: 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
--
The list of stable paper currencies built by central bankers is as
short as the list of stable democracies built by armed invaders.
-- Bill Bonner
 
Reply With Quote
 
 
 
 
JimJx
Guest
Posts: n/a
 
      09-28-2007
On Sep 28, 10:33 am, (E-Mail Removed) (Greg Bacon) wrote:
> In article <(E-Mail Removed). com>,
> JimJx <(E-Mail Removed)> wrote:
>
> : 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
> --
> The list of stable paper currencies built by central bankers is as
> short as the list of stable democracies built by armed invaders.
> -- Bill Bonner


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

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      09-28-2007

Quoth JimJx <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
Greg Bacon
Guest
Posts: n/a
 
      09-28-2007
In article <(E-Mail Removed) .com>,
JimJx <(E-Mail Removed)> wrote:

: On Sep 28, 10:33 am, (E-Mail 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
--
To admit that labor needs protection is to acknowledge its inferiority.
-- Henry George, Protection or Free Trade
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      09-28-2007
On Fri, 28 Sep 2007 06:10:54 -0700, JimJx wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to sort and omit duplicates in a list using javascript Laphan ASP General 2 02-12-2008 06:23 PM
Datalist HeaderTemplate repeating duplicates? - sort, break, grouping? jobs at webdos ASP .Net 2 10-08-2006 01:22 PM
Merge multiple rows and remove duplicates --based on the first value Susan Perl Misc 6 01-27-2006 07:21 PM
remove duplicates from list *preserving order* Steven Bethard Python 11 02-07-2005 09:34 AM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments