You are here: Re: trouble doing a join using WHERE and getting the right info when using GROUP BY « PHP SQL « IT news, forums, messages
Re: trouble doing a join using WHERE and getting the right info when using GROUP BY

Posted by ZeldorBlat on 12/15/05 05:07

Everything that's not an aggregate and appears in your select list
should also be in your group by (in general). This version should also
return all records, even when they have no comments. I did it here to
be consistent with the query you already had, but I'd advise against
the *= syntax.

Anyway, I think you want something like this:

SELECT tagCloud.id, tagCloud.url, tagCloud.item, tagCloud.headline,
tagCloud.description, tagCloud.tag1, tagCloud.tag2, tagCloud.tag3,
tagCloud.tag4, tagCloud.tag5, tagCloud.tag6, visitors.date,
comments.belongsToWhichPage, count(comment.id) howManyComments
FROM tagCloud, visitors, comments
WHERE tagCloud.visitorId = visitors.id
AND tagCloud.id *= comments.belongsToWhichPage
AND ( tag1 = 'photography' || tag2 = 'photography' || tag3 =
'photography' || tag4 = 'photography' || tag5 = 'photography' || tag6
= 'photography' )
GROUP BY tagCloud.id, tagCloud.url, tagCloud.item, tagCloud.headline,
tagCloud.description, tagCloud.tag1, tagCloud.tag2, tagCloud.tag3,
tagCloud.tag4, tagCloud.tag5, tagCloud.tag6, visitors.date,
comments.belongsToWhichPage
ORDER BY tagCloud.id DESC;

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация