From: | ed(dot)prochak(at)magicinterface(dot)com (Ed prochak) |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Query |
Date: | 2004-06-16 18:14:07 |
Message-ID: | 4b5394b2.0406161014.2dbdf9f8@posting.google.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
dayzman(at)hotmail(dot)com (Michael) wrote in message news:<48e30213(dot)0406152231(dot)6e19331c(at)posting(dot)google(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Chris Browne | 2004-06-16 18:14:25 | Re: why no answer? [Fwd: backup and restore just with use of jdbc?] |
Previous Message | Ben | 2004-06-16 18:11:58 | Re: Tracking down deadlocks |