php - 如何在 Codeigniter 中使用 except 代码进行选择

标签 php mysql database codeigniter

这就是我在 SQL 中想要的:select id from mytable except select id from another_table,

但是配合CI的数据库库要使用EXCEPT函数, 我如何获得它?

最佳答案

您可以使用 NOT EXISTS 完成此操作

SELECT
    MT.id
FROM
    mytable AS MT
WHERE NOT EXISTS (
    SELECT
        AT.id
    FROM another_table AS AT 
    WHERE AT.id = MT.id
)

关于php - 如何在 Codeigniter 中使用 except 代码进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38588373/

相关文章:

一张表有两个外键的MySQL数据库

c++ - 如何在C/C++中保存数据?

php - 为什么 mySQL concat 在不同的平台上会失败?

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

requireonce中的PHP绝对路径

PHP:将导入的文本大写

Mysql EF存储过程,没有生成C#部分

php - 按升序编写查询正值和负值

mysql - 将列中的字符串的一部分复制到 MYSQL 中的另一个字符串

sql - DB2 - SQL-将结果限制为某个列中某个值仅出现几次