Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 23rd, 2005, 01:10 AM
Michael
Guest
 
Posts: n/a
Default Query

Hi,
If I have R(a integer PRIMARY KEY, b text, c text, d integer); and I
want to find how many different entries there are, (specified using b
and c instead of a), is "select count(distinct b||c) from R" an
appropriate query? Also, if I want to find how many of those that have
a different "d", can I use "select count(d) from R goup by title ||
author"? What if b and c are integers, then I wouldn't be able to
concatenate the 2 fields right?

Please help.

Thanks,
Michael
  #2  
Old November 23rd, 2005, 01:11 AM
Ed prochak
Guest
 
Posts: n/a
Default Re: Query

dayzman@hotmail.com (Michael) wrote in message news:<48e30213.0406152231.6e19331c@posting.google. com>...[color=blue]
> Hi,
> If I have R(a integer PRIMARY KEY, b text, c text, d integer); and I
> want to find how many different entries there are, (specified using b
> and c instead of a), is "select count(distinct b||c) from R" an
> appropriate query?[/color]
(see note 1 below)[color=blue]
> ... Also, if I want to find how many of those that have
> a different "d", can I use "select count(d) from R goup by title ||
> author"?[/color]
(see note 2)[color=blue]
> ... What if b and c are integers, then I wouldn't be able to
> concatenate the 2 fields right?[/color]
(note 3, you see the patern by now)[color=blue]
>
> Please help.
>
> Thanks,
> Michael[/color]

Taking a summer school class?

(BTW, I personally hate the DISTINCT keyword, mainly because it is so
easily abused.)

Here are some things to think about:
Note 1: concatenating two text fields can bring incorrect results,
imagine these values for your query:
b c
XY Z
X YZ
your query, as written considers those two rows the same. Are they the
same? (depends on your application! your answer may be YES.)

Note 2: where did the "title" and "author" attributes come from?? IOW,
if you are making an example, be consistent within the example.

Note 3: Why would changing b and c to integers make a difference to
the LOGIC of the query? Isn't 123 a character string?


I'm not trying to hassle you. Just trying to help you Think it
through.

Ed
  #3  
Old November 23rd, 2005, 01:11 AM
Ed prochak
Guest
 
Posts: n/a
Default Re: Query

dayzman@hotmail.com (Michael) wrote in message news:<48e30213.0406152231.6e19331c@posting.google. com>...[color=blue]
> Hi,
> If I have R(a integer PRIMARY KEY, b text, c text, d integer); and I
> want to find how many different entries there are, (specified using b
> and c instead of a), is "select count(distinct b||c) from R" an
> appropriate query?[/color]
(see note 1 below)[color=blue]
> ... Also, if I want to find how many of those that have
> a different "d", can I use "select count(d) from R goup by title ||
> author"?[/color]
(see note 2)[color=blue]
> ... What if b and c are integers, then I wouldn't be able to
> concatenate the 2 fields right?[/color]
(note 3, you see the patern by now)[color=blue]
>
> Please help.
>
> Thanks,
> Michael[/color]

Taking a summer school class?

(BTW, I personally hate the DISTINCT keyword, mainly because it is so
easily abused.)

Here are some things to think about:
Note 1: concatenating two text fields can bring incorrect results,
imagine these values for your query:
b c
XY Z
X YZ
your query, as written considers those two rows the same. Are they the
same? (depends on your application! your answer may be YES.)

Note 2: where did the "title" and "author" attributes come from?? IOW,
if you are making an example, be consistent within the example.

Note 3: Why would changing b and c to integers make a difference to
the LOGIC of the query? Isn't 123 a character string?


I'm not trying to hassle you. Just trying to help you Think it
through.

Ed
  #4  
Old November 23rd, 2005, 01:11 AM
Laconic2
Guest
 
Posts: n/a
Default Re: Query


"Michael" <dayzman@hotmail.com> wrote in message
news:48e30213.0406152231.6e19331c@posting.google.c om...[color=blue]
> Hi,
> If I have R(a integer PRIMARY KEY, b text, c text, d integer); and I
> want to find how many different entries there are, (specified using b
> and c instead of a), is "select count(distinct b||c) from R" an
> appropriate query?[/color]


Try:

select count(1) from
(select distinct b, c from R);

However, your prof may not like this answer.



  #5  
Old November 23rd, 2005, 01:11 AM
Laconic2
Guest
 
Posts: n/a
Default Re: Query


"Michael" <dayzman@hotmail.com> wrote in message
news:48e30213.0406152231.6e19331c@posting.google.c om...[color=blue]
> Hi,
> If I have R(a integer PRIMARY KEY, b text, c text, d integer); and I
> want to find how many different entries there are, (specified using b
> and c instead of a), is "select count(distinct b||c) from R" an
> appropriate query?[/color]


Try:

select count(1) from
(select distinct b, c from R);

However, your prof may not like this answer.



 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles