ich stecke bei einer Query fest:
Ich habe einen Join mit mehreren Where clauses und für das Resultset einer where - clause benötige ich nur die ersten 3 Einträge.
Der Einfachheit halber ein Beispiel:
Select c.id, c.gruppe, c.datum, c.bild, c.online, c.aktiv
from cms c
where datum >= heute … etc
and (c.aktiv=1 and c.gruppe =„news“ or c.gruppe=„aktion“)
order by d.datum desc
dies ergibt ein Resultset von sagen wir
14 Einträgen,
9 davon sind news
5 sind aktion
ich brauche aber nur jeweils die ersten 3 Einträge von News und Aktion
mit Group by und having count hatte ich keinen Erfolg.
Hoffe jemand hat eine Idee wie man das lösen kann.
SELECT * FROM
(
SELECT TOP 3
c.id
, c.gruppe
, c.datum
, c.bild
, c.online
, c.aktiv
FROM cms c
WHERE datum >= heute ..... etc
AND c.aktiv = 1
AND c.gruppe = 'news'
ORDER BY c.datum DESC
UNION
SELECT TOP 3
c.id
, c.gruppe
, c.datum
, c.bild
, c.online
, c.aktiv
FROM cms c
WHERE datum >= heute ..... etc
AND c.aktiv = 1
AND c.gruppe = 'aktion'
ORDER BY c.datum DESC
) AS tmp
ORDER BY tmp.datum DESC