>Is there a way I
>can do a IF((SELECT.....), expr2, expr3) and have expr2 populate with
>whatever is returned from the select statement?
Yes, select if( (select count(*) from mytable ) > 100, 1, 0) works fine.
The alias inside your last If(...), though, is not visible outside its
parentheses; why not move that join logic to the query's main clause?
On 7/8/2010 9:59 AM, John Nichel wrote to:
> I'm hoping what I'm trying to do can be done, but I can't seem to find
> the right syntax. I have the following query:
> a.local_stock = 'y' || a.is_commercial =
> 'n' || freight_class = '', 'y', 'n'
> ) as local_stock,
> pricing b
> a.productid = b.productid
> )> 1, 'y', 'n'
> ) as price_breaks,
> a.productid in (select c.productid from
> variants c), 'y', 'n'
> ) as is_variant,
> a.forsale = 'N', 'y', 'n'
> ) as disabled,
> orders d
> left join
> order_details e
> d.orderid = e.orderid
> e.productid =
> order by
> d.date desc
> limit 1
> )> 0, d.date, 0
> ) as last_sold
> products a
> The query is erroring out on 'd.date' in expression two of the if
> statement, "#1109 - Unknown table 'd' in field list". Is there a way I
> can do a IF((SELECT.....), expr2, expr3) and have expr2 populate with
> whatever is returned from the select statement? Thank you.
> John C. Nichel IV
> System Administrator
> 716.362.9212 x16
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.439 / Virus Database: 271.1.1/2989 - Release Date: 07/08/10 06:36:00