Jump to content


Photo

#1054 - Unknown column 'xxxx' in 'on clause'


  • Please log in to reply
9 replies to this topic

#1 rcouser

rcouser

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 22 October 2013 - 06:18 AM

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.



#2 gristoi

gristoi

    Advanced Member

  • Members
  • PipPipPip
  • 842 posts

Posted 22 October 2013 - 07:00 AM

youve got return_id in your query and returns_id in your table structure ( missing s)


To err is human... to really foul up requires the root password

#3 rcouser

rcouser

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 22 October 2013 - 08:08 AM

sorry that was my typo.it is return_id



#4 gristoi

gristoi

    Advanced Member

  • Members
  • PipPipPip
  • 842 posts

Posted 22 October 2013 - 08:15 AM

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?


To err is human... to really foul up requires the root password

#5 rcouser

rcouser

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 22 October 2013 - 08:22 AM

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



#6 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,538 posts

Posted 22 October 2013 - 08:49 AM

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.


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#7 rcouser

rcouser

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 22 October 2013 - 08:53 AM

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'



#8 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,538 posts

Posted 22 October 2013 - 09:09 AM

that error message is coming from some other query.


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#9 rcouser

rcouser

    Advanced Member

  • Members
  • PipPipPip
  • 53 posts

Posted 22 October 2013 - 09:34 AM

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'



#10 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,373 posts
  • LocationCheshire, UK

Posted 22 October 2013 - 11:07 AM

If you alias the tables you need to reference their column using that alias

 

returns.id should be t1.id


moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com