字段列表中的Mysql列'nume'是模糊错误

时间:2015-10-31 01:00:02

标签: mysql

select nume as "Nume", adresa as "Adresa",localitate as "Localitatea"
from info 
left join angajati 
on id_i = id_a
where localitate like "Orhei" 
and year(curdate()) - year(data_nast) >=50

我有两个带有数字字段的表,我收到了错误,请帮助我现在不知道为什么这段代码不起作用!!!

2 个答案:

答案 0 :(得分:1)

您需要定义nume字段应来自哪个表。这是使用表别名的一种方式:

select i.nume as "Nume", 
       adresa as "Adresa",
       localitate as "Localitatea"
from info i 
    left join angajati a on id_i = id_a
where localitate like "Orhei" 
     and year(curdate()) - year(data_nast) >=50

使用joins时,如果在多个表中表示相同的字段,则必须定义要引用的表。

答案 1 :(得分:0)

由于您要加入id_iid_a列,因此两个nume列在联接结果中是不同的。指定您的意思是哪个表的nume列:

SELECT info.nume AS "Nume" ...

SELECT angajati.nume AS "Nume" ...