Reputation: 6025
I have a scenario where I'm calculating something in the WHERE
clause of my SQL, but I also want to get that calculation - since it's expensive. Is it possible to get the results of something done in the WHERE
clause, like this:
SELECT `foo` FROM `table` WHERE (foo = LongCalculation(`column`))
Wishful thinking, or possible with MySQL?
EDIT: Calculation is column dependent
Upvotes: 2
Views: 97
Reputation: 6025
A bit of re-working @cherouvim's idea and I got it to work with row-dependent functions:
set @bar = 0;
SELECT
`product_name`,
@bar AS `stock`
FROM `jos_vm_product`
WHERE (@bar := `product_in_stock`) > 0
Upvotes: 1
Reputation: 31903
set @bar = LongCalculation();
select foo from table where foo=@bar;
Upvotes: 3