Hi.
On Fri, Sep 07, 2001 at 07:12:47PM +0200, [EMAIL PROTECTED] wrote:
> Hello,
> How can I limit the query to those rows where "SUM(value) as Tot > 0".
> If I put it in an where clause it get an error.
That is to be expected, as in SQL the WHERE clause is evaluated before
the SELECT clause (i.e. the fields) are read at all. So SUM(value) is
not defined at the time the WHERE clause is evaluated.
Expression which depend on the selected fields can/have to be written
in the HAVING clause.
> So how to do that
SELECT id,url,title,description,top,keyword,SUM(value) as Tot
FROM links LEFT JOIN keywords ON links.id=keywords.LinkId
GROUP BY id
HAVING Tot > 0
ORDER BY tot DESC
This should work.
Bye,
Benjamin.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php