Quote:
Originally Posted by JarlH
Odd, I just checked MS SQL Server, DB2 and MySQL, and none of them complained.
|
Extremely odd...
Postgres:
Code:
c:\>psql
Aktive Codepage: 1252.
psql (8.4.1)
Type "help" for help.
postgres=> create table group_test (id integer primary key, some_column varchar(20));
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "group_test_pkey" for table "group_test"
CREATE TABLE
postgres=> select id, count(*) from group_test group by some_column;
ERROR: column "group_test.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select id, count(*) from group_test group by some_column;
^
postgres=>
Oracle:
Code:
C:\temp>sqlplus scott/tiger@oradb
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Dec 10 22:39:52 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the OLAP and Data Mining options
SQL> create table group_test (id integer primary key, some_column varchar(20));
Table created.
SQL> select id, count(*) from group_test group by some_column;
select id, count(*) from group_test group by some_column
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression
SQL>
DB2 (9.7)
Code:
c:\temp>db2 connect to sample
Database Connection Information
Database server = DB2/NT 9.7.0
SQL authorization ID = DB2ADMIN
Local database alias = SAMPLE
c:\temp>db2 create table group_test (id integer not null primary key, some_column varchar(20))
DB20000I The SQL command completed successfully.
c:\temp>db2 select id, count(*) from group_test group by some_column
SQL0119N An expression starting with "ID" specified in a SELECT clause,
HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or
it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column
function and no GROUP BY clause is specified. SQLSTATE=42803
c:\temp>
SQL Server 2005
Code:
c:\temp>osql -S WALLACE\SQLEXPRESS -U myuser
Password:
1> create table group_test (id integer primary key, some_column varchar(20))
2> go
1> select id, count(*) from group_test group by some_column
2> go
Msg 8120, Level 16, State 1, Server WALLACE\SQLEXPRESS, Line 1
Column 'group_test.id' is invalid in the select list because it is not contained in either an aggregate function or the
GROUP BY clause.
1>