PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : left join und count



msi
04-04-2004, 22:36
Hallo,

ich habe eine mysql query in der art:

select t1.name,count(t2.tid) from table1 as t1 left join table2 as t2 on t1.id=t2.tid group by t1.id

das funktioniert auch wunderbar, wenn ich das count allerdings bei where reinbringe scheitert er und sagt mir, dass ich group by nicht richtig verwende:

select t1.name from table1 as t1 left join table2 as t2 on t1.id=t2.tid where count(t2.tid)<2 group by t1.id

woran liegt das? mach ich irgendwas falsch oder kann mysql das einfach nicht?

danke Markus

elrond
05-04-2004, 08:08
ist einfach eine Frage der Gruppierung...

willst Du Aggregatfunktionen wie count() oder max() zur Auswahl benutzen, geht das nur im "having" Teil

select t1.name, t2.tid from table1 as t1 left join table2 as t2 on t1.id=t2.tid where group by t1.name,t2tid having count(t2.tid)<2


ggf. nochmal unter "having" ins manual schaun ...