From 097d3604233e058171d46c67539ffd18bf596e54 Mon Sep 17 00:00:00 2001 From: Stefan Koch Date: Tue, 30 Jul 2013 11:18:13 +0200 Subject: [PATCH] MAX in WHERE not possible You cannot use MAX() in a WHERE clause, instead use a subquery. The ORDER BY is also unneeded, because we only select the maximum. So what to order, there is only one number (even if multiple entries with the same number). --- documents/musterloesung-db-klausur-b/d3e.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/documents/musterloesung-db-klausur-b/d3e.sql b/documents/musterloesung-db-klausur-b/d3e.sql index 82531ec..5536778 100644 --- a/documents/musterloesung-db-klausur-b/d3e.sql +++ b/documents/musterloesung-db-klausur-b/d3e.sql @@ -1,5 +1,4 @@ SELECT berater_id, name, anzahl FROM Beratungsanzahl JOIN Berater ON Berater.berater_id = Beratungsanzahl.berater_id - WHERE anzahl = MAX(anzahl) - ORDER BY anzahl DESC + WHERE anzahl = (SELECT MAX(anzahl) FROM Beratungsanzahl)