简体   繁体   English

where子句中的列“ u_id”不明确

[英]Column 'u_id' in where clause is ambiguous

SELECT  `attendence`.`u_id` ,
        DATE_FORMAT(date,'%d-%m-%Y') as  `date`,
        `attendence`.`checkin`, 
        `attendence`.`checkout`,
         `users`.`firstname`,
         `users` .`lastname`
 FROM  `attendence`
 INNER JOIN  `users` ON  `attendence`.`u_id` = `users`.`u_id`
 WHERE  DATE_FORMAT( DATE,  '%Y-%m' ) =  '$combined' AND `u_id`='$u_id';

please help guys 请帮助大家

when i removed AND u_id ='#u_id it works but returns all employee details' 当我删除AND u_id ='#u_id时,它可以工作,但返回所有员工详细信息'

you need to specify what table should the column u_id came from since both tables has this column. 您需要指定u_idu_id来自哪个表,因为两个表都具有该列。

AND `attendence`.`u_id`='$u_id';

OR 要么

AND `users`.`u_id`='$u_id';

choose one that satifies your needs. 选择一种满足您需求的产品。 Anyway, either of the two functions the same since they are the linking columns of both tables. 无论如何,这两个函数之一是相同的,因为它们是两个表的链接列。

replace 更换

`u_id`='$u_id';

by 通过

`users`.`u_id`='$u_id';

If you have u_id in multiple tables that you are using in your query then you need to specify which u_id you want to use. 如果在查询中使用的多个表中都有u_id ,则需要指定要使用的u_id

use this in your where clause: 在where子句中使用它:

`attendence`.`u_id` = '$u_id';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM