where 子句中的列“id"不明确

Column #39;id#39; in where clause is ambiguous(where 子句中的列“id不明确)
本文介绍了where 子句中的列“id"不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<块引用>

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

SELECT `leads`.*,`customers`.`id` 作为customers_id,`customers`.`name` AS customers_name,`customers`.`company` 作为customers_company,`customers`.`email` 作为customers_email,`customers`.`phone` 作为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`哪里`id` = '3'AND `leads`.`id` = '1'LIMIT 1

<块引用>

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

行号:12

函数如下所示:

function get($id){$this->db->select('leads.*,customers.id AScustomers_id,customers.name AScustomers_name,customers.company AScustomers_company,customers.email AScustomers_email,customers.phone AScustomers_phone,customers.created_at AScustomer_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 = Lead.customer_id');$this->db->limit(1);$query = $this->db->get();如果 ($query->num_rows() == 1){$result = $query->result();返回 $result[0];}}

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

怎么了?

解决方案

WHERE id = '3'

您没有指定 id 字段来自哪个表.您的意思是:

WHERE customer.id = '3'

条件将是 customer.id 而不是 id

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

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

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

Line Number: 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();

What is wrong?

解决方案

WHERE id = '3'

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

WHERE customer.id = '3'

condition will be customer.id instead of id

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)