有如下的数据表:
application_daily 11万条数据
application_info400多条数据
查询结果数据为19498
来看下mysql 子查询的例子。
例1,子查询 (0.01s)
复制代码 代码示例:
select sql_no_cache * from application_daily where application_info_id in
(select id from application_info where Team_TeamID=3)
例2,子查询 (0.002s)
复制代码 代码示例:
select sql_no_cache * from application_daily where application_info_id in
(161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190)
例3,连接查询,两条语句等价(0.001s)
复制代码 代码示例:
select sql_no_cache * from application_daily,application_info where
Team_TeamID=3 and application_daily.application_info_id=application_info.id
select sql_no_cache * from application_daily inner join application_info on
(application_daily.application_info_id=application_info.id) where Team_TeamID=3
小结:在子查询时,尽量避免使用in条件。
您可能感兴趣的文章:
mysql子查询的实例总结
mysql多表子查询与左连接的代码
mysql子查询使用EXISTS命令的例子
mysql子查询中EXISTS用法的例子
mysql子查询的五种方式
mysql子查询的用法举例
mysql update实现子查询的实例分享
mysql in 子查询效率慢的优化方法详解