Re: using COUNT in a WHERE

2004-04-27 Thread Michael Stassen
Sagi Bashari wrote: Michael Stassen wrote: No, you can't use an alias in the WHERE clause. Even if you could, you'd have a problem here. The WHERE clause is used to decide which rows to look at in advance of any calculations. You're asking mysql to count the rows which match the WHERE cla

Re: using COUNT in a WHERE

2004-04-27 Thread Egor Egorov
Sagi Bashari <[EMAIL PROTECTED]> wrote: > Michael Stassen wrote: > >> No, you can't use an alias in the WHERE clause. Even if you could, >> you'd have a problem here. The WHERE clause is used to decide which >> rows to look at in advance of any calculations. You're asking mysql >> to count t

Re: using COUNT in a WHERE

2004-04-26 Thread Sagi Bashari
Off the top of my head, I'm sure you'd do it like this: SELECT products.id, COUNT(orders.id) AS hits FROM products, orders WHERE orders.product_id = products.id AND hits >= products.quantity GROUP BY products.id Tried that: ERROR 1054: Unknown column 'hits' in 'where clause'

Re: using COUNT in a WHERE

2004-04-26 Thread Sagi Bashari
Michael Stassen wrote: No, you can't use an alias in the WHERE clause. Even if you could, you'd have a problem here. The WHERE clause is used to decide which rows to look at in advance of any calculations. You're asking mysql to count the rows which match the WHERE clause, but you're also as