简体   繁体   English

字段列表中的“名称”列不明确

[英]Column 'name' in field list is ambiguous

 <?php 
$cid=$_REQUEST['cn'];
 $sid=$_REQUEST['sn'];
 $query="select name,NAME from products a,category b where a.category_id=$cid and a.store_id=$cid and a.category_id=b.ID ";

 $result=  mysqli_query($link, $query)or die(mysqli_error($link));
?> 

i write simple program,it showing the following error. 我写了一个简单的程序,它显示以下错误。 if i mention name as products.name then it shows unknown column products.name. 如果我提到名称为products.name,那么它将显示未知列products.name。

the main error is Column 'name' in field list is ambiguous 主要错误是字段列表中的列“名称”不明确

You need to prepend the selected columns since you are doing a query over multiple tables containing columns with the same name eg.: 您需要在选定的列之前添加前缀,因为您要对包含相同名称的列的多个表进行查询,例如:

select a.name as prod_name,b.NAME as cat_name 
from products a,category b 
  where a.category_id=$cid 
  and a.store_id=$cid 
  and a.category_id=b.ID

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

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