Sorry, mailed it in html format. Read answer below

-------- Original Message --------
Subject:        Re: Where clause question
Date:   Tue, 12 Oct 2004 00:00:12 +0200
From:   Morten Egan <[EMAIL PROTECTED]>
To:     Ed Lazor <[EMAIL PROTECTED]>
CC:     [EMAIL PROTECTED]



Not knowing how the "inards" of mysql works, I would say the having clause is usually slow, and if done correctly you actually dont execute the calculation twice, because the parser should recognize this as beeing the same as what you've specified in your select part.

/morten

Ed Lazor wrote:

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

?



-----Original Message-----
Great explanation. By the way, Ed, what you might be looking
for is the HAVING clause, which culls records right before
the LIMIT is applied.

SELECT ID, Title, MSRP, Price, round( ( (MSRP - Price) / MSRP) * 100) as discount
FROM `products`
HAVING discount > 10
LIMIT 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