Bug #38859 | limiting a group - LIMITGROUP | ||
---|---|---|---|
Submitted: | 18 Aug 2008 14:17 | Modified: | 19 Aug 2008 9:07 |
Reporter: | Lig Isler-Turmelle | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Parser | Severity: | S4 (Feature request) |
Version: | 6.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[18 Aug 2008 14:17]
Lig Isler-Turmelle
[19 Aug 2008 8:31]
Susanne Ebrecht
More standard conform test where system don't through errors (name field was too short for data input). CREATE TABLE roster ( id serial NOT NULL, name VARCHAR(100) NOT NULL, role VARCHAR(10) NOT NULL, date DATETIME NOT NULL, team_id INT NOT NULL, points INT NOT NULL, PRIMARY KEY(id)); INSERT INTO roster(name, role, date, team_id, points) VALUES ('John Black', 'coach', '2008-01-01 00:00:01', 1, 0); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Jack Black', 'coach', '2008-01-01 00:00:02', 2, 0); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Joe Smoe', 'player', '2008-01-01 00:00:03', 1, 2); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Jane Smoe', 'player', '2008-01-01 00:00:04', 1, 3); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Harry Smith', 'player', '2008-01-01 00:00:05', 1, 1); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Jay Thompson', 'player', '2008-01-01 00:00:06', 1, 2); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Philip Hass', 'player', '2008-01-01 00:00:03', 2, 2); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Julie Hass', 'player', '2008-01-01 00:00:04', 2, 3); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Janet Phillips', 'player', '2008-01-01 00:00:05', 2, 1); INSERT INTO roster(name, role, date, team_id, points) VALUES ('Fred Clause', 'player', '2008-01-01 00:00:06', 2, 4);
[19 Aug 2008 9:07]
Susanne Ebrecht
LIMIT is not defined at SQL Standard. I think this feature request makes sense. Maybe this Syntax will match better: SELECT ... FROM ... WHERE ... GROUP BY ... ORDER BY ... LIMIT BY GROUP, LIMIT I mean: [[LIMIT [BY GROUP][DERIVED {GROUP | ALL}] number][,...]] Default: LIMIT DERIVED ALL This would give the possibilities: - you can LIMIT the rows for the groups - you can LIMIT the resulted groups - you can LIMIT the result of all returned rows And you can list more then one LIMIT. Example: without limit your result will be 5 groups with 5 rows for every group. Now you want to get only three rows from every group and only the first two groups: LIMIT BY GROUP 3, LIMIT DERIVED GROUP 2 If you want to get a result set of 3 rows per group and not more then 15 rows output in total: LIMIT BY GROUP 3, LIMIT DERIVED ALL 15 or because default is LIMIT DERIVED ALL you can use: LIMIT BY GROUP 3, LIMIT 15
[19 Aug 2008 10:09]
Susanne Ebrecht
Bug #38857 is just another use case for this new feature.