博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql not in 和 left join比较
阅读量:6859 次
发布时间:2019-06-26

本文共 1955 字,大约阅读时间需要 6 分钟。

hot3.png

mysql> select User.userName from User where userId not in (select userId from Article ); +----------+ | userName | +----------+ | xiaolin | +----------+ 1 row in set (0.03 sec)

mysql> explain select User.userName from User where userId not in (select userId from Article ); +----+--------------------+---------+------+---------------+------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+--------------------+---------+------+---------------+------+---------+------+------+-------------+ | 1 | PRIMARY | User | ALL | NULL | NULL | NULL | NULL | 4 | Using where | | 2 | DEPENDENT SUBQUERY | Article | ALL | NULL | NULL | NULL | NULL | 11 | Using where | +----+--------------------+---------+------+---------------+------+---------+------+------+-------------+ 2 rows in set (0.00 sec)

mysql> select cc.userName from (select User.*,Article.userId as tempcolum from User left join Article on User.userId=Article.userId) as cc where cc.tempcolum is null; +----------+ | userName | +----------+ | xiaolin | +----------+ 1 row in set (0.02 sec)

mysql> explain select cc.userName from (select User.*,Article.userId as tempcolum from User left join Article on User.userId=Article.userId) as cc where cc.tempcolum is null; +----+-------------+------------+------+---------------+------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+------------+------+---------------+------+---------+------+------+-------------+ | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 12 | Using where | | 2 | DERIVED | User | ALL | NULL | NULL | NULL | NULL | 4 | | | 2 | DERIVED | Article | ALL | NULL | NULL | NULL | NULL | 11 | | +----+-------------+------------+------+---------------+------+---------+------+------+-------------+

转载于:https://my.oschina.net/u/242853/blog/170455

你可能感兴趣的文章
隐藏当前Activity而不关闭
查看>>
Navicat Premium 12.0.18安装与激活(转)
查看>>
LLVM与Clang的一些事儿
查看>>
问题总结
查看>>
深度解析利用ES6进行Promise封装总结
查看>>
零基础的你还在纠结怎么学习Python编程吗?
查看>>
Flask在Windows环境下的部署
查看>>
力扣(LeetCode)56
查看>>
图片懒加载通俗易懂
查看>>
浅析vue2.0的diff算法
查看>>
协方差深入解读
查看>>
使用Node.js和WebHDFS REST API访问Hadoop HDFS数据
查看>>
聊聊flink Table的Over Windows
查看>>
基本排序算法
查看>>
分布式系统关注点——想通关「限流」?只要这一篇
查看>>
Java™ 教程(接口)
查看>>
一些简单的数组排序算法
查看>>
使用Spring AOP和自定义注解进行参数检查
查看>>
WMS项目中使用到的注解
查看>>
聊聊Java对象在内存中的大小
查看>>