Article 5AY4H [SQLite] Why more records with/without GROUP BY?

[SQLite] Why more records with/without GROUP BY?

by
littlebigman
from LinuxQuestions.org on (#5AY4H)
Hello,

This is an SQL(ite) newbie question.

I found data on how people commute in my area.

The database holds two tables: One where the actual data lives, and a second with the familiar, two-column ZIP=city name.

I'd like to know how many people in my hometown (zip 12345) drive to work (mode 3), and where.

For some reason, SQLite doesn't return the same number of rows depending on my (not) using GROUP BY:

Code:SELECT COUNT(commute.ZIP_WORK) FROM commute WHERE commute.ZIP_RESIDENCE=12345 AND commute.MODE=3;
=> 1559 records

SELECT COUNT(commute.ZIP_WORK) FROM commute,zip WHERE commute.ZIP_RESIDENCE=12345 AND commute.MODE=3 AND commute.ZIP_WORK=zip.ZIP;
=> 1559 records

SELECT COUNT(commute.ZIP_WORK) FROM commute,zip WHERE commute.ZIP_RESIDENCE=12345 AND commute.MODE=3 AND commute.ZIP_WORK=zip.ZIP GROUP BY commute.ZIP ORDER BY COUNT(commute.ZIP);
=> 1763 records

SELECT COUNT(commute.ZIP_WORK) FROM commute,zip FROM commute JOIN zip ON commute.ZIP_WORK=zip.ZIP WHERE commute.ZIP_RESIDENCE=12345 AND commute.MODE=3 GROUP BY commute.ZIP ORDER BY COUNT(commute.ZIP);
=> 1763 recordsAny idea why?

Thank you.
Attached Thumbnailsattachment.php?attachmentid=34693&stc=1& latest?d=yIl2AUoC8zA latest?i=BOdxzan-0l4:nF_xOHe5bV0:F7zBnMy latest?i=BOdxzan-0l4:nF_xOHe5bV0:V_sGLiP latest?d=qj6IDK7rITs latest?i=BOdxzan-0l4:nF_xOHe5bV0:gIN9vFwBOdxzan-0l4
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments