Vinzenz Mai: SELECT bei phpBB-Forum (Beispiel)

Beitrag lesen

Hallo Stefan,

Da "Thread 5" zweimal drin ist, soll "Thread 5" nur einmal erscheinen und eben "Thread 1" nachrücken, da "Limit 5"! Wie muss ich das SELECT nun umbauen? Mit DISTINCT und GROUP BY funktioniert das nicht!

Sicher?
Sollte eigentlich mit "group by post_id" und "having max(post_time)" klappen.

das ist meiner Meinung nach ein schlechter Ratschlag. Solches SQL akzeptiert nur MySQL. Nur unter bestimmten Bedingungen (die hier allerdings gegeben sein sollten) gibt es das gewünschte Ergebnis. Ich zitiere aus dem Handbuch:

<zitat>
In standard SQL, you would have to add customer.name to the GROUP BY clause. In MySQL, the name is redundant.

Do not use this feature if the columns you omit from the GROUP BY part are not constant in the group. The server is free to return any value from the group, so the results are indeterminate unless all values are the same.
</zitat>

Genau dieses "Do not use this feature ..." führt hier im Forum zu ständigen Fragen, weil es mißachtet wird. Ich persönlich bevorzuge die Formulierung:

"Do not use this feature at all."

Freundliche Grüße

Vinzenz