MySQL where 子句中的列“id”不明确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22632441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Column 'id' in where clause is ambiguous
提问by Casperlarsen
I get this error and I can't figure out why?
我收到此错误,但不知道为什么?
Error Number: 1052
Column 'id' in where clause is ambiguous
错误编号:1052
where 子句中的列“id”不明确
SELECT `leads`.*,
`customers`.`id` AS customers_id,
`customers`.`name` AS customers_name,
`customers`.`company` AS customers_company,
`customers`.`email` AS customers_email,
`customers`.`phone` AS customers_phone,
`customers`.`created_at` AS customers_created_at,
`customers`.`updated_at` AS customers_updated_at,
`customers`.`ip_address` AS customers_ip_addressFROM (`leads`)
JOIN `customers` ON `customers`.`id` = `leads`.`customer_id`
WHERE `id` = '3'
AND `leads`.`id` = '1'LIMIT 1
Filename: /home/www/REMOVED/models/lead.php
Line Number: 12
文件名:/home/www/REMOVED/models/lead.php
行号:12
The function looks like this:
该函数如下所示:
function get($id)
{
$this->db->select('leads.*, customers.id AS customers_id, customers.name AS customers_name, customers.company AS customers_company, customers.email AS customers_email, customers.phone AS customers_phone, customers.created_at AS customers_created_at, customers.updated_at AS customers_updated_at, customers.ip_address AS customers_ip_address');
$this->db->where('leads.id', '1');
$this->db->from('leads');
$this->db->join('customers', 'customers.id = leads.customer_id');
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1)
{
$result = $query->result();
return $result[0];
}
}
And line 12 is $query = $this->db->get();
第 12 行是 $query = $this->db->get();
What is wrong?
怎么了?
回答by Geoff Williams
WHERE id = '3'
You don't specify which table the id field is coming from. Did you mean:
您没有指定 id 字段来自哪个表。你的意思是:
WHERE customer.id = '3'