rcouser Posted October 22, 2013 Share Posted October 22, 2013 Hi, Get an unknown column error but the code looks fine, wondering if someone else can see anything i'm missing: Table: returns id (primary) reference account_number Table: returns_items id (primary) returns_id qty gas_type SELECT * FROM returns t1 LEFT JOIN returns_items t2 ON t1.id = t2.return_id WHERE (t1.order_date >= '2013-08-01') Any help much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/ Share on other sites More sharing options...
gristoi Posted October 22, 2013 Share Posted October 22, 2013 youve got return_id in your query and returns_id in your table structure ( missing s) Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454918 Share on other sites More sharing options...
rcouser Posted October 22, 2013 Author Share Posted October 22, 2013 sorry that was my typo.it is return_id Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454944 Share on other sites More sharing options...
gristoi Posted October 22, 2013 Share Posted October 22, 2013 what is the exact error. unkown xxxxx is not too helpful. is it actually giving you a column name? and where is order_date in the t1 structure? Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454945 Share on other sites More sharing options...
rcouser Posted October 22, 2013 Author Share Posted October 22, 2013 Error is: #1054 - Unknown column 'returns.id' in 'on clause' And yes sorry order_date is in the returns table, i forget that when typing my message Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454947 Share on other sites More sharing options...
mac_gyver Posted October 22, 2013 Share Posted October 22, 2013 programming is an exact science. so far in this thread, your table definition, query, and error message don't match up and due to typos on your part no one here knows which name for the column is correct. you should be copy/pasting actual information if you want someone in a help forum to be able to help you. Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454949 Share on other sites More sharing options...
rcouser Posted October 22, 2013 Author Share Posted October 22, 2013 Table: returns --- id (primary) reference account_number order_date Table: returns_items --- id (primary) return_id qty gas_type SELECT * FROM returns t1 LEFT JOIN returns_items t2 ON t1.id = t2.return_id WHERE (t1.order_date >= '2013-08-01') Error is: #1054 - Unknown column 'returns.id' in 'on clause' Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454951 Share on other sites More sharing options...
mac_gyver Posted October 22, 2013 Share Posted October 22, 2013 that error message is coming from some other query. Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454952 Share on other sites More sharing options...
rcouser Posted October 22, 2013 Author Share Posted October 22, 2013 SELECT * FROM returns t1 LEFT JOIN returns_items t2 ON t1.id = t2.return_id WHERE (t1.order_date >= '2013-08-01') OR SELECT * FROM returns t1 LEFT JOIN returns_items t2 ON returns.id = returns_items.return_id WHERE (t1.order_date >= '2013-08-01') Same error only the unknown column 'returns.id' changes. If I change it to: SELECT * FROM returns t1 LEFT JOIN returns_items t2 ON returns_items.return_id = returns.id WHERE (t1.order_date >= '2013-08-01') The unknown column becomes 'returns_items.return_id' Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454953 Share on other sites More sharing options...
Barand Posted October 22, 2013 Share Posted October 22, 2013 If you alias the tables you need to reference their column using that alias returns.id should be t1.id Quote Link to comment https://forums.phpfreaks.com/topic/283182-1054-unknown-column-xxxx-in-on-clause/#findComment-1454966 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.