views:

38

answers:

1

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.

+2  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
)
Unreason
That is giving me:Unknown column 'outter.FOO' in 'where clause'
gaoshan88
Sorry, getting tired. Edited in place.
Unreason
Bingo... that did it. Thanks, go get some sleep.
gaoshan88