In fact there is a (major) diference!
Using "GROUP BY" we get a faster query results than "DISTINCT",
because with "DISTINCT" we have several full scans on the table.
With "GROUP BY" we only have one full scan getting better performance
results.




-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: sexta-feira, 10 de Janeiro de 2003 15:26
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Why can't use SQL "GROUP BY..."?


I just tried this command in Oracle:
        select status_flag from status_table group by status_flag

and it produced the same output as
        select distinct status_flag from status_table

I suspect, though I haven't confirmed this, that the two SQL commands are
optimized to the same strategy by Oracle.  I'm not really sure why you would
want to use GROUP BY rather than a DISTINCT clause here.  (This is under
Oracle 8.1.7, so YMMV with other databases.)

The error message Gary is receiving is suggesting that $Table is blank.

What is the exact code, Gary?  Your message suggests that your code is
similar to the snippet you included.  Is that the code verbatim?  If not,
could you post a snippet from the actual code.

Cheers!

Gordon Dewis
Production Officer / Agent de production
Geography Division / Division de la géographie
Statistics Canada / Statistique Canada
(613)951-4591

-----Original Message-----
From: Philip Newton [mailto:[EMAIL PROTECTED]]
Sent: January 10, 2003 00:34
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: Why can't use SQL "GROUP BY..."?


On Thu, 9 Jan 2003 22:59:03 +0800 (CST), [EMAIL PROTECTED] (Gary fung)
wrote:

> My coding is similar as:
> 
>  $value2 = $dbh->prepare("SELECT page FROM $Table 
> 
> GROUP BY page") || die "Couldn't add record, ".$dbh->errstr();
> 
> Whenever I use "GROUP BY.." , an error statement will go out :
> 
> "SQL ERROR: Can't find table names in FROM clause!"

Others have pointed out the possibility that $Table may be empty. I'd
like to add that I think there's another error -- as far as I know,
GROUP BY can only be used when you have aggregate functions such as SUM,
MAX, COUNT(...) etc. (For example, "SELECT custno, count(ordernum) FROM
orders GROUP BY custno ORDER BY 2 DESC" to select the customers together
with the number of orders, grouped by customer but sorted by number of
orders.)

Did you mean ORDER BY, perhaps?

Cheers,
Philip

Reply via email to