Thread: Query

Query

From
dayzman@hotmail.com (Michael)
Date:
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

Re: Query

From
ed.prochak@magicinterface.com (Ed prochak)
Date:
dayzman@hotmail.com (Michael) wrote in message news:<48e30213.0406152231.6e19331c@posting.google.com>...
> 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?
(see note 1 below)
> ... 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"?
(see note 2)
> ... What if b and c are integers, then I wouldn't be able to
> concatenate the 2 fields right?
(note 3, you see the patern by now)
>
> Please help.
>
> Thanks,
> Michael

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

Re: Query

From
"Laconic2"
Date:
"Michael" <dayzman@hotmail.com> wrote in message
news:48e30213.0406152231.6e19331c@posting.google.com...
> 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?


Try:

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

However, your prof may not like this answer.