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
我有两个带有数字字段的表,我收到了错误,请帮助我现在不知道为什么这段代码不起作用!!!
答案 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_i
和id_a
列,因此两个nume
列在联接结果中是不同的。指定您的意思是哪个表的nume
列:
SELECT info.nume AS "Nume" ...
或
SELECT angajati.nume AS "Nume" ...