如何获取table_1中不在table_2中的id
我的 table 看起来像这种类型。
表_1
---------------------------------------------
| id | user |
---------------------------------------------
| 1 | Jack |
---------------------------------------------
| 2 | John |
---------------------------------------------
表_2
------------------------------------------
| web_id | website |
------------------------------------------
| 2 | Facebook |
------------------------------------------
| 3 | Google+ |
------------------------------------------
我想要codeigniter查询
$this->db->select("*");
$this->db->from("table_1");
$this->db->where_not_in('id', "table_2.web_id");
return $this->db->get();
最佳答案
试试这个
SELECT id
FROM table_1
WHERE id NOT IN
(
SELECT web_id FROM table_2 WHERE 1
);
使用 CodeIgniter Active Records 查询如下
$this->db->select('*');
$this->db->where('id NOT IN (SELECT web_id FROM table_2 WHERE 1)', NULL, FALSE);
$query = $this->db->get('table_1');
关于php - 如何获取表2中没有的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19221155/