简体   繁体   English

字段列表中的MySQL列“ nume”是模棱两可的错误

[英]Mysql Column 'nume' in field list is ambiguous error

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

I have 2 tables with nume field and i'm getting the error, please help i don't now why this code didn't work !!! 我有2个带有nume字段的表,但出现了错误,请帮助我现在不理解为什么此代码不起作用!

You need to define which table the nume field should be coming from. 您需要定义nume字段应来自哪个表。 Here's one way using a table alias: 这是使用表别名的一种方法:

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

When using joins , if the same field is represented in multiple tables, you have to define which table you are referring to. 使用joins ,如果在多个表中表示相同的字段,则必须定义要引用的表。

Since you are joining on the id_i and id_a columns, the two nume columns are distinct in the joined result. 由于您要在id_iid_a列上进行id_i ,因此两个nume列在联接结果中是不同的。 Specify which table's nume column you mean: 指定您要表示的表的nume列:

SELECT info.nume AS "Nume" ...

or 要么

SELECT angajati.nume AS "Nume" ...

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

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