加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – NOT IN运算符不适用于mysql中的非主键值

发布时间:2020-12-13 18:16:47 所属栏目:PHP教程 来源:网络整理
导读:我读过很多关于NOT IN运算符的Q A’ If I use IN operator to filter NULL values and white spaces It is not working Why? 还有很多其他问题,但问题是当我们在运算符中不使用非主键时,它不会返回响应. SELECT * FROM temp_customers WHERE temp_customers.
我读过很多关于NOT IN运算符的Q& A’
If I use IN operator to filter NULL values and white spaces It is not working Why?
还有很多其他问题,但问题是当我们在运算符中不使用非主键时,它不会返回响应.
SELECT * FROM temp_customers WHERE temp_customers.fk_my_id NOT IN (SELECT fk_my_id FROM customers)

其中fk_my_id是非主键,可能是一个字符串.

有什么想法吗?

在这里使用group_concat用逗号分隔fk_my_id
SELECT * FROM temp_customers WHERE temp_customers.fk_my_id NOT IN 
(SELECT GROUP_CONCAT(fk_my_id) FROM customers)   
# when fk_my_id is INTEGER output (1,2)

SELECT * FROM temp_customers WHERE temp_customers.fk_my_id NOT IN 
(SELECT GROUP_CONCAT("'",fk_my_id,"'") FROM customers)   
# when fk_my_id is VARCHAR output ('1','2')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读