Consider a table:

 

create table book (book_id integer primary key, type varchar, title
varchar);

 

and some data for it:

 

insert into book (book_id, type, title) 

values (1, 'hardback', 'book 1')

;

insert into book (book_id, type, title) 

values (2, 'softback', 'book 2')

;

 

Now execute the following SQL:

 

select type, count(*)

from book

;

 

Which gives the result: 

type                       count(*)

softback               2

 

I would have expected an error message here to the effect that a non
aggregate value was not part of the grouping.

The result is strange and misleading and can easily lead to data errors.

 

The SQL statement should have been:

select type, count(*)

from book

group by type

;

 

Which gives:

type                       count(*)

hardback             1

softback               1

 

 

 

Best regards,

 

Frank Missel

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to