Ah. Well that's a different question. You can, in fact, use
aliases in ORDER BY (and GROUP BY):

SELECT ID, Title, MSRP, Price, round( ( (MSRP - Price) / MSRP) * 100) AS discount
FROM products
ORDER BY discount ASC
LIMIT 10


Now, regarding HAVING, I would imagine the HAVING clause
would be faster, assuming you actually want the value of
discount in the result of the SELECT. Otherwise, you're
doing the calculation twice. No idea if that's true, though,
so maybe someone else can give a definitive answer.

____________________________________________________________
Eamon Daly



----- Original Message ----- From: "Ed Lazor" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, October 11, 2004 4:51 PM
Subject: RE: Where clause question



Interesting.  I thought you could sort by aliases.  Thanks Shawn.

The easy answer was to just add the calculation to the where section as
well.  But which approach is faster - "having" or the calculation?

Ie.

select ID, Title, MSRP, Price, round( ( (MSRP - Price) / MSRP) * 100) as
discount from products where round( ( (MSRP - Price) / MSRP) * 100) > 10

- OR -

select ... HAVING discount > 10

?


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to