2015-10-31 43 views
0
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個表與字段和我得到的錯誤,請幫助我現在不現在爲什麼這段代碼沒有工作!Mysql字段列表中的'nume'是模棱兩可的錯誤

回答

0

由於您加入id_iid_a列,因此兩個nume列在連接結果中是不同的。指定您的意思是該表的nume列:

SELECT info.nume AS "Nume" ... 

SELECT angajati.nume AS "Nume" ... 
+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,如果同一字段在多個表來表示,你必須定義你指的是哪個表。

+0

感謝您的幫助! –

+0

mysql正在返回一個空結果集(即零行)可能是我搞砸了,請幫助!我想去睡覺... –

相關問題