Q:

MySQL - Using an alias in a subquery with WHERE clause

I have a feeling I am completely borking this MySQL query but I'll ask anyway. I am wondering why I get the warning Unknown column 'FOO', and how I can get this query to work properly, in 'where clause' when I run the following:
SELECT sample_id AS FOO 
FROM   tbl_test 
WHERE  sample_id = 521 
       AND sample_id IN (SELECT sample_id 
                         FROM   tbl_test 
                         WHERE  sample_id = FOO 
                         GROUP  BY sample_id) 

Edit This query works fine on a different server and fails as described above on the new server. The old one was v 5.0.45 and the new one is 5.0.75.

A:

SELECT sample_id 
FROM   tbl_test outter 
WHERE  sample_id = 521 
       AND sample_id IN (SELECT sample_id 
                         FROM   tbl_test 
                         WHERE  sample_id = outter.sample_id 
                         GROUP  BY sample_id) 

