Ik heb de volgende tabellen en query. Met de query wil ik alle weblog posts ophalen van user 27. Ook wil ik zien wat de naam van deze gebruiker is en hoeveel comments er op zijn posts zijn geleverd.
Deze geeft alleen een foutmelding: "user error: Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause". Dus ik heb toen toegevoegd:
code:
Ik heb nu de volgende query: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| +----------------------------------------------+ | weblog_posts | +----+-------+------+---------+----------+-----+ | id | title | body | created | category | uid | +----+-------+------+---------+----------+-----+ +-------------------+ | weblog_categories | +----+--------------+ | id | name | +----+--------------+ +-------------+ | users | +-----+-------+ | uid | name | +-----+-------+ +---------------------+ | weblog_comments | +----+---------+------+ | id | post_id | body | +----+---------+------+ |
SQL:
1
2
3
4
5
6
7
8
| SELECT wp.*, u.name, wc.name AS category, COUNT(wt.post_id) AS num_comments FROM weblog_posts wp, users u, weblog_categories wc, weblog_comments wt WHERE wp.uid = u.uid AND wp.category = wc.id AND wp.id = wt.post_id AND wp.uid = 27 ORDER BY wp.created DESC LIMIT 0, 5 |
Deze geeft alleen een foutmelding: "user error: Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause". Dus ik heb toen toegevoegd:
SQL:
...maar dan krijg ik maar 1 post terug, terwijl user 27, 9 posts in de database heeft staan met comments op elke post. Wie kan mij zeggen waar het fout gaat?
1
| GROUP BY wp.id |
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."