dbTalk Databases Forums  

Queries that includes clientid that exists more than once in a table and also only once in the table

comp.databases.ms-access comp.databases.ms-access


Discuss Queries that includes clientid that exists more than once in a table and also only once in the table in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
PW
 
Posts: n/a

Default Queries that includes clientid that exists more than once in a table and also only once in the table - 09-01-2011 , 02:54 PM






Hi,

I am having trouble trying to figure out how to build two queries:

One that lists only clientids that exist in the reservation table just
once.

And a query that lists clientids in the reservation table that exist
more than once.

Any ideas?

Thanks,

-paulw

Reply With Quote
  #2  
Old   
Arvin Meyer
 
Posts: n/a

Default Re: Queries that includes clientid that exists more than once in a table and also only once in the table - 09-01-2011 , 04:13 PM






SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))=1));

SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))>1));

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://access.mvps.org
Co-author: "Access Solutions", published by Wiley



"PW" <emailaddyinsig (AT) ifIremember (DOT) com> wrote

Quote:
Hi,

I am having trouble trying to figure out how to build two queries:

One that lists only clientids that exist in the reservation table just
once.

And a query that lists clientids in the reservation table that exist
more than once.

Any ideas?

Thanks,

-paulw

Reply With Quote
  #3  
Old   
ron paii
 
Posts: n/a

Default Re: Queries that includes clientid that exists more than once in a table and also only once in the table - 09-01-2011 , 04:18 PM



SELECT reservation .[ClientID], Count(reservation .[ClientID]) AS
[CountOfClientID]
FROM reservation
GROUP BY reservation .[ClientID]
HAVING (((Count(reservation .[ClientID]))>1));

SELECT reservation .[ClientID], Count(reservation .[ClientID]) AS
[CountOfClientID]
FROM reservation
GROUP BY reservation .[ClientID]
HAVING (((Count(reservation .[ClientID]))=1));


"PW" <emailaddyinsig (AT) ifIremember (DOT) com> wrote

Quote:
Hi,

I am having trouble trying to figure out how to build two queries:

One that lists only clientids that exist in the reservation table just
once.

And a query that lists clientids in the reservation table that exist
more than once.

Any ideas?

Thanks,

-paulw

Reply With Quote
  #4  
Old   
PW
 
Posts: n/a

Default Re: Queries that includes clientid that exists more than once in a table and also only once in the table - 09-01-2011 , 05:52 PM



On Thu, 1 Sep 2011 17:13:31 -0400, "Arvin Meyer" <arvinm (AT) invalid (DOT) org>
wrote:

Quote:
SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))=1));

SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))>1));

Thank you both! I totally forgot about the HAVING clause and also
count.

Reply With Quote
  #5  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: Queries that includes clientid that exists more than once in a table and also only once in the table - 09-03-2011 , 03:35 PM



PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in
news:f13067l2tamb6hh01m6s1fd2ku1fpf21hd (AT) 4ax (DOT) com:

Quote:
On Thu, 1 Sep 2011 17:13:31 -0400, "Arvin Meyer"
arvinm (AT) invalid (DOT) org> wrote:

SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))=1));

SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))>1));

Thank you both! I totally forgot about the HAVING clause and also
count.
If you'd write your queries in the Access query designer, it will
use HAVING any time you put criteria under an aggregated field
(unless you specifically choose WHERE from the dropdown list).

I am really convinced that most people don't use the QBE enough --
it makes many, many things MUCH easier...

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #6  
Old   
PW
 
Posts: n/a

Default Re: Queries that includes clientid that exists more than once in a table and also only once in the table - 09-03-2011 , 11:22 PM



On Sat, 3 Sep 2011 20:35:20 +0000 (UTC), "David-W-Fenton"
<NoEmail (AT) SeeSignature (DOT) invalid> wrote:

Quote:
PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in
news:f13067l2tamb6hh01m6s1fd2ku1fpf21hd (AT) 4ax (DOT) com:

On Thu, 1 Sep 2011 17:13:31 -0400, "Arvin Meyer"
arvinm (AT) invalid (DOT) org> wrote:

SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))=1));

SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))>1));

Thank you both! I totally forgot about the HAVING clause and also
count.

If you'd write your queries in the Access query designer, it will
use HAVING any time you put criteria under an aggregated field
(unless you specifically choose WHERE from the dropdown list).

I am really convinced that most people don't use the QBE enough --
it makes many, many things MUCH easier...
David. I guess I am old fashioned but I do realize the power of the MS
Access query designer. My wife is very good at it but I keep trying to
do things in code I suppose. At least when I can't figure it out!

Thanks so much.

-paul

Reply With Quote
  #7  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: Queries that includes clientid that exists more than once in a table and also only once in the table - 09-07-2011 , 06:38 PM



PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in
news:qru5675v0re4osnmhktvjcaure7rlg7j6e (AT) 4ax (DOT) com:

Quote:
On Sat, 3 Sep 2011 20:35:20 +0000 (UTC), "David-W-Fenton"
NoEmail (AT) SeeSignature (DOT) invalid> wrote:

PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in
news:f13067l2tamb6hh01m6s1fd2ku1fpf21hd (AT) 4ax (DOT) com:

On Thu, 1 Sep 2011 17:13:31 -0400, "Arvin Meyer"
arvinm (AT) invalid (DOT) org> wrote:

SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))=1));

SELECT *
FROM tblReservation
GROUP BY ClientID
HAVING (((Count(ClientID))>1));

Thank you both! I totally forgot about the HAVING clause and
also count.

If you'd write your queries in the Access query designer, it will
use HAVING any time you put criteria under an aggregated field
(unless you specifically choose WHERE from the dropdown list).

I am really convinced that most people don't use the QBE enough --
it makes many, many things MUCH easier...

David. I guess I am old fashioned but I do realize the power of
the MS Access query designer. My wife is very good at it but I
keep trying to do things in code I suppose. At least when I can't
figure it out!
Avail yourself of the assistance Access provides! Don't write your
SQL by hand!

I usually start my SQL in the query designer when I'm going to use
it in code. I especially avoid writing JOINs by hand, since the
Access syntax is so picky about parens and order.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.