where子句中的列"id"不明确 [英] Column 'id' in where clause is ambiguous

查看:353
本文介绍了where子句中的列"id"不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误,我不知道为什么吗?

I get this error and I can't figure out why?

错误号:1052
where子句中的"id"列不明确

Error Number: 1052
Column 'id' in where clause is ambiguous

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

文件名:/home/www/REMOVED/models/lead.php

Filename: /home/www/REMOVED/models/lead.php

行号:12

函数如下:

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];
  }
}

第12行是$query = $this->db->get();

怎么了?

推荐答案

WHERE id = '3'

您不指定id字段来自哪个表.你是说:

You don't specify which table the id field is coming from. Did you mean:

WHERE customer.id = '3'

这篇关于where子句中的列"id"不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆