Welcome Guest, Not a member yet? Register   Sign In
database Error Number: 1052
#1

[eluser]Unknown[/eluser]
Hello all
im trying to execute sql statement that retrieve data from two tables that have same column name which is id
to distinguish between the id from t_employees table i added t_employees.id in the where statement but my problem is that it does not appears in the SQL statement,what i write is:
$where=array('t_employees.id'=>$id);
but i still get the follwing error:

A Database Error Occurred

Error Number: 1052

Column 'id' in where clause is ambiguous

SELECT *, `t_employees`.`id` id FROM (`t_employees`) JOIN `t_descriptions` ON `t_descriptions`.`id` = `t_employees`.`t_descriptions_id` WHERE `id` = '24' ORDER BY `t_employees`.`id` asc
i dont know why it appears id=24 although i add t_employees.id in the where statement
can any body help me
thanks
#2

[eluser]mddd[/eluser]
Maybe the problem is not the WHERE but the SELECT part.

You say:
Code:
SELECT *, t_employees.id id
. Here you create an alias 'id' for the field t_employees.id. That's why in the WHERE clause 'id' is used: it is the alias that you selected!

Change the alias name. Then you can choose: use the WHERE clause with the full name (table.column) or the alias. Both will work.
#3

[eluser]Rahul Anand[/eluser]
add the table name before the * like t_employees.*, may be that is creating problem. check this and let me know if this help



Thanks
Rahul Anand
[email protected]
#4

[eluser]danmontgomery[/eluser]
the "Column X in where clause is ambiguous" means you have two or more columns called 'id' in your result set, and need to specify the table (in the where clause, not necessarily in the select).




Theme © iAndrew 2016 - Forum software by © MyBB