HyderA
HyderA

Reputation: 21371

What's wrong with this query?

SELECT u.user_id, u.first_name, u.last_name, i.path AS image_path 
FROM bgy_users u
LEFT JOIN bgy_images i ON i.image_id = u.image_id 
WHERE u.commentary_id = '0'

Error:

Unknown column 'u.image_id' in 'on clause'

When there definitely is a column image_id in table bgy_users

What am I doing wrong?

Result for DESCRIBE BGY_USERS

alt text

Result for DESCRIBE BGY_IMAGES

alt text

Upvotes: 2

Views: 173

Answers (4)

Kailash Badu
Kailash Badu

Reputation: 416

This is real weird and the only thing I can think of is that you are querying the wrong database. Confirm in your application code that you are using correct connection string to connect to the database.

You can also issue 'select database()' from your application to find out the name of the current database you are connected to.

Upvotes: 0

James Anderson
James Anderson

Reputation: 27478

Can you do a

select image_id from bgy_users;

I am asking because the only time I have seen anything like this it has either been a code page problem or there have been non printable characters creeping into your query.

Upvotes: 0

Marek Karbarz
Marek Karbarz

Reputation: 29294

try this

SELECT u.user_id, u.first_name, u.last_name, i.path AS image_path 
FROM (bgy_users u)
LEFT JOIN (bgy_images i) ON i.image_id = u.image_id 
WHERE u.commentary_id = '0'

the only difference is the parenthesis around table names

Upvotes: 0

Ahmed Memon
Ahmed Memon

Reputation: 319

The query is perfectly alright mySQL 5.0.18-nt-log. Such error will be prompted only when the field does not exist, in case double check your column name image_id in bgy_users table.

Upvotes: 1

Related Questions