dbTalk Databases Forums  

Query

comp.databases comp.databases


Discuss Query in the comp.databases forum.



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

Default Query - 06-16-2004 , 01:31 AM






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

Reply With Quote
  #2  
Old   
Ed prochak
 
Posts: n/a

Default Re: Query - 06-16-2004 , 01:14 PM






dayzman (AT) hotmail (DOT) com (Michael) wrote in message news:<48e30213.0406152231.6e19331c (AT) posting (DOT) google.com>...
Quote:
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


Reply With Quote
  #3  
Old   
Laconic2
 
Posts: n/a

Default Re: Query - 06-16-2004 , 03:35 PM




"Michael" <dayzman (AT) hotmail (DOT) com> wrote

Quote:
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.





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 - 2013, Jelsoft Enterprises Ltd.