I have written a query on three tables that share the common key named id. When the values are returned from the inner select statements,the outer select is not able to resolve the id. I looked at the posts in stackoverflow like the one below: [1052: Column 'id' in field list is ambiguous
It recommends that we use aliases to disambiguate the problem, however it does'nt seem to be working for me. Following is my query in mysql.
SELECT
e2.`exchange_code`
e1.`id`,
e1.`error_time`,
e1.`last_update_time`
FROM
`exchange_error_details` e1,
`exchange_products` e2
WHERE e1.`id` IN
(SELECT
id
FROM
exchange_products)
AND e1.`id` NOT IN
(SELECT
id
FROM
mdd_suppressed_keys)
AND e1.`clear_time` IS NULL
Edit:
exchange_error_details
id error_time clear_time last_update_time clear_ref_ticker
ADF.10052.1.Q.FEED 2014-11-25 10:36:25 \N 2014-11-25 02:36:25 THD
ADF.10052.1.Q.FEED 2014-11-28 13:50:06 2014-11-28 13:50:37 2014-11-28 13:49:51 AMLP
ADF.10052.1.Q.FEED 2014-11-28 13:53:08 2014-11-28 13:53:38 2014-11-28 13:52:44 ONVO
ADF.10052.1.Q.FEED 2014-11-28 13:55:09 2014-11-28 13:56:10 2014-11-28 13:54:54 ACAD
ADF.10052.1.Q.FEED 2014-11-28 13:58:10 2014-11-28 13:58:41 2014-11-28 13:57:56 HABT
exchange_products:
id exchange_code iso_code issue_type
ADF.10052.1.Q.FEED 10052 ADF 1
ADF.10052.1.T.FEED 10052 ADF 1
ADF.10074.1.T.FEED 10074 ADF 1
ADF.11099.1.T.FEED 11099 ADF 1
ADF.11099.14.T.FEED 11099 ADF 14
mdd_suppressed_keys
id user date
ADF.10052.1.Q.FEED droy 2015-03-09 03:16:22
HAM.17.41.Q.FEED droy 2015-03-09 03:16:26
HAM.17.41.T.FEED droy 2015-03-09 03:16:30
IND.114.1.T.FEED droy 2015-03-09 03:16:22
SWX.4.41.Q.FEED droy 2015-03-09 03:16:22
Error Message
1 queries executed, 0 success, 1 errors, 0 warnings
Query: select e2.`exchange_code`, e1.`id`, e1.`error_time`, e1.`last_update_time` from `exchange_error_details` e1, `exchange_products`...
Error Code: 1052
Column 'id' in field list is ambiguous
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0.388 sec
Why I wrote this query:
I wish to return only those values from the exchange_error_details table whose id field matches the one in the exchange_products table and exclude out the ones present in the mdd_suppressed_keys table.
Thanks!