首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >给一个list查询哪些在表中哪些不在

给一个list查询哪些在表中哪些不在

原创
作者头像
葫芦
修改2022-04-13 00:39:20
修改2022-04-13 00:39:20
1.1K0
举报
文章被收录于专栏:葫芦葫芦

给一个list查询哪些在表中哪些不在

select values from a list return that are in table and that are not in table

数据库 mysql

测试表

test table

name

wz

hl


查询的列表

select list

[ 'xm' ,'xw' ,'xl' ,'wz' ,'bt' ,'hh']


查询语句

select sql

代码语言:javascript
复制
select temp.name,if(temp.name = test.name,1,0) as 'is_null' from   (
select 'xm' as name
union all select 'xw'
union all select 'xl'
union all select 'wz'
union all select 'bt'
union all select 'hh'
) as temp
left join test on temp.name=test.name

return

name

is_null

xm

0

xw

0

xl

0

wz

1

bt

0

hh

0


葫芦的运维日志-王梓个人博客

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 给一个list查询哪些在表中哪些不在
  • select values from a list return that are in table and that are not in table
    • 测试表
    • test table
    • 查询的列表
    • select list
    • 查询语句
    • select sql
  • 葫芦的运维日志-王梓个人博客
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档