Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
863 views
in Technique[技术] by (71.8m points)

mysql - Column 'id' in where clause is ambiguous

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...