As far as the above query, I do not see a reason to group by ...
Logically it doesn't make sense to exclude a column in the GROUP BY Clause but have in the SELECT List .. consider a simple example: A table has three columns, continent, country, sex ... Now you wish to know the number of males and females, then you will do
select sex,count(*) from table1 group by sex
select country,sex,count(*) from table1 group by sex
The second query will not be able to give logically correct result... Do you agree ??
But, if you want to see the result only for Europe, you can say
select 'Europe',country,sex,count(*) from table1 where continent='Europe' group by 'Europe',country,sex
or to make it more generic
select continet,country,sex,count(*) from table1 where continent='Europe' group by continent,country,sex
So, if you add a column to the display and you know the value of the column, then include it as a column in the select list
Last edited by sathyaram_s; 08-11-04 at 15:41.
Visit the new-look IDUG Website , register to gain access to the excellent content.