Thursday, March 2, 2017

Any way to force Mysql to use column from select in where clause when column is ambiguous?

I have query:

select products.* from products
join companies on companies.id = products.company_id
where id = 1;

query generates error "Column 'id' in where clause is ambiguous". I know that column is ambiguous, but I want tell mysql to look only columns in select "products.". So if I have "products." id from products will be examined in where clause, if I have "companies." id from companies will be examined in where clause, if I have "products., companies.*" only then id will be ambiguous.

This is just plain example, query is more complicated and generated by ORM. I know I can use

select products.id as products_id from products

and then use

where products_id  = 1

but this does not fit to my needs because query is generated by orm. Any ideas ?




via fico7489

Advertisement