Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Select syntax to find multi entries?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
GarryJones  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 22:01
Newsgroups: comp.databases.mysql
From: GarryJones <mor...@algonet.se>
Date: Wed, 4 Nov 2009 14:01:54 -0800 (PST)
Local: Wed 4 Nov 2009 22:01
Subject: Select syntax to find multi entries?
If this is my data in table fruitlist with columns username & fruit

Smith, lemon
Anderson, orange
Henly, apple
Anderson, pear

SELECT * FROM fruitlist

... gives me the data so I can (with some added code) write the
following output

"Smith chose lemon, Anderson chose orange, Henly chose apple, Anderson
chose pear"

But now I am only interested in the rows that have a user in it twice.

What I need is SELECT * FROM fruitlist WHERE username (exists more
than once)

The output I want to create should be

"Anderson chose orange and pear, this needs some action...... "

So my questions is what is the syntax for

SELECT * FROM fruitlist WHERE username (exists more than once)

Thanks for any help in this matter

Garry Jones
Sweden


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jerry Stuckle  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 01:49
Newsgroups: comp.databases.mysql
From: Jerry Stuckle <jstuck...@attglobal.net>
Date: Wed, 04 Nov 2009 20:49:14 -0500
Local: Thurs 5 Nov 2009 01:49
Subject: Re: Select syntax to find multi entries?

This is one place where a subselect outdoes a join:

SELECT f1.userid, f1.fruit
FROM fruitlist f1
WHERE f1.userid IN {
   SELECT f2.userid
   FROM fruitlist f2
   GROUP BY f2.userid
   HAVING count(f2.userid) > 1);

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 04:19
Newsgroups: comp.databases.mysql
From: "Richard" <root@localhost>
Date: Thu, 5 Nov 2009 05:19:48 +0100
Local: Thurs 5 Nov 2009 04:19
Subject: Re: Select syntax to find multi entries?

"GarryJones" <mor...@algonet.se> wrote in message

news:5b2dddb5-4b83-4c35-961c-c59bf9cd8b75@s31g2000yqs.googlegroups.com...

Hi,
How about:
SELECT * FROM fruitlist WHERE COUNT(username) > 1

or

SELECT * FROM fruitlist HAVING COUNT(username) > 1

R.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew C.  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 08:45
Newsgroups: comp.databases.mysql
From: "Andrew C." <nonse...@totally.made.up>
Date: Thu, 5 Nov 2009 08:45:55 -0000
Local: Thurs 5 Nov 2009 08:45
Subject: Re: Select syntax to find multi entries?

"GarryJones" <mor...@algonet.se> wrote in message

news:5b2dddb5-4b83-4c35-961c-c59bf9cd8b75@s31g2000yqs.googlegroups.com...

> If this is my data in table fruitlist with columns username & fruit

> Smith, lemon
> Anderson, orange
> Henly, apple
> Anderson, pear

Fruit?

Has someone mentioned the strawberry query yet? ;-)

A.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
toby  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 15:39
Newsgroups: comp.databases.mysql
From: toby <t...@telegraphics.com.au>
Date: Thu, 5 Nov 2009 07:39:32 -0800 (PST)
Local: Thurs 5 Nov 2009 15:39
Subject: Re: Select syntax to find multi entries?
On Nov 4, 11:19 pm, "Richard" <root@localhost> wrote:

Neither of these will work.

You mean:
SELECT COUNT(*) AS cnt FROM fruitlist GROUP BY username HAVING cnt > 1


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 19:22
Newsgroups: comp.databases.mysql
From: "Richard" <root@localhost>
Date: Thu, 5 Nov 2009 20:22:59 +0100
Local: Thurs 5 Nov 2009 19:22
Subject: Re: Select syntax to find multi entries?

"toby" <t...@telegraphics.com.au> wrote in message

news:01dc7da8-83b7-4f6c-bf30-d53aedcace8e@p23g2000vbl.googlegroups.com...
On Nov 4, 11:19 pm, "Richard" <root@localhost> wrote:

Neither of these will work.

You mean:
SELECT COUNT(*) AS cnt FROM fruitlist GROUP BY username HAVING cnt > 1

====================
end post
====================

Well, no, not really.
Yeah, the count() needs a group by, but not the username:

> > But now I am only interested in the rows that have a user in it
> > twice.

I took this as he wants to get all those rows, so grouping on username
wouldnt do it.

GROUP BY (any_unique_column_or_expression) would solve that?

Maybe even a "random" value.

R.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
toby  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 20:57
Newsgroups: comp.databases.mysql
From: toby <t...@telegraphics.com.au>
Date: Thu, 5 Nov 2009 12:57:47 -0800 (PST)
Local: Thurs 5 Nov 2009 20:57
Subject: Re: Select syntax to find multi entries?
On Nov 5, 2:22 pm, "Richard" <root@localhost> wrote:

If he wants the rows themselves, then just use a self join...
SELECT L.*
FROM fruitlist L LEFT JOIN fruitlist R
         ON R.username = L.username AND R.fruit <> L.fruit
WHERE R.username IS NOT NULL


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 21:06
Newsgroups: comp.databases.mysql
From: "Richard" <root@localhost>
Date: Thu, 5 Nov 2009 22:06:36 +0100
Local: Thurs 5 Nov 2009 21:06
Subject: Re: Select syntax to find multi entries?

"toby" <t...@telegraphics.com.au> wrote in message

news:52c6ae10-6cbc-4476-b670-2223eaafdd90@h26g2000vbr.googlegroups.com...
On Nov 5, 2:22 pm, "Richard" <root@localhost> wrote:

If he wants the rows themselves, then just use a self join...
SELECT L.*
FROM fruitlist L LEFT JOIN fruitlist R
         ON R.username = L.username AND R.fruit <> L.fruit
WHERE R.username IS NOT NULL

> GROUP BY (any_unique_column_or_expression) would solve that?

> Maybe even a "random" value.

> R.

I dont understand why you need the join?
The results are the same, not?

R.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
toby  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 21:56
Newsgroups: comp.databases.mysql
From: toby <t...@telegraphics.com.au>
Date: Thu, 5 Nov 2009 13:56:15 -0800 (PST)
Local: Thurs 5 Nov 2009 21:56
Subject: Re: Select syntax to find multi entries?
On Nov 5, 4:06 pm, "Richard" <root@localhost> wrote:

The same as what? I don't see where you were heading with your
suggestions above, can you paste a complete working query?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jerry Stuckle  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 22:24
Newsgroups: comp.databases.mysql
From: Jerry Stuckle <jstuck...@attglobal.net>
Date: Thu, 05 Nov 2009 17:24:38 -0500
Local: Thurs 5 Nov 2009 22:24
Subject: Re: Select syntax to find multi entries?

Toby,

What happens if you have:

Smith, lemon
Anderson, orange
Henly, apple
Anderson, pear
Anderson, peach
Anderson, kumquat

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erick T. Barkhuis  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 07:04
Newsgroups: comp.databases.mysql
From: "Erick T. Barkhuis" <erick.use-...@ardane.c.o.m>
Date: 6 Nov 2009 07:04:29 GMT
Local: Fri 6 Nov 2009 07:04
Subject: Re: Select syntax to find multi entries?
GarryJones:

I don't think this is what you want, because there are no rows that
have the same user (or any user) in it twice.

>What I need is SELECT * FROM fruitlist WHERE username (exists more
>than once)

>The output I want to create should be

>"Anderson chose orange and pear, this needs some action...... "

What do you want your query to do (and the output to be) when your
table contains:

 Henly, apple
 Anderson, pear
 Henly, apple
 Anderson, pear
 Henly, apple
 Anderson, pear

?

Usually, denizens at this group are quite good at asking questions
first, before coming up with a proposed query. I wonder what caused the
absense of such questions now. Perhaps the fact that the OP hasn't
returned to the thread yet?

--
Erick


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google