Bill Karwin wrote:
Quote:
No bother wrote:
Quote:
>Select (select b.baitID from b where b.entrydate curdate()) as
>wantedBaitIDs from bait_tbl b;
>
Does something like this do what you want?
>
SELECT IF(b.entrydate curdate(), b.baitID, NULL) AS wantedBaitIDs
FROM bait_tbl AS b;
>
Can you be more specific about the more complex case? It's hard to
visualize what you're describing unless we know the join conditions, etc.
>
>
Regards,
Bill K.
No, I specifically thought I needed to use a subquery.
Select
max(if(b.baittype = 'Worms',(select count(b.baitID) where b.entrydate <
curdate(),0) as 'Worms',
max(if(b.baittype = 'Lure', (select count(b.baitID) where b.entrydate >
curdate(),0) as 'Lure',
max(if(b.baittype = 'Other',(select count(b.baitID) where
b.baitDistributor = 'A Retailor Near You'),0) as 'Other'
from bait_tbl b inner join customer_tbl c on b.baitID = c.PreferedBaitID
As you can see the specific criteria to be used depends on the baittype.
All I really want to know is if I can refer to an alias so designated in
the outmost from clause from within a subquery in the select clause. In
the first example I gave the alias is defined outside of the subquery.
Mysql does not recognize that the table alias in the subquery means the
table outside of the subquery.