您的位置:首页 > 数据库 > MySQL

mysql 查询优化 in 和 not in

2018-03-29 14:52 489 查看
select title.id,title.`name` from title where title.id not in (select user_tag.tagid from user_tag )


可以改为

select title.id,title.`name`
from title
left join user_tag on user_tag.tagid = title.id
where user_tag.id is null


select title.id,title.`name` from title where title.id in (select user_tag.tagid from user_tag )


可以改为

select title.id,title.`name`
from title
inner join user_tag on user_tag.tagid = title.id
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: