Home > php教程 > php手册 > SQL中in或or与union all性能对比

SQL中in或or与union all性能对比

WBOY
Release: 2016-05-25 16:43:27
Original
1195 people have browsed it

//使用or,代码如下: 
WHERE * FROM article  
WHERE article_category=2  
OR article_category=3  
ORDER BY article_id DESC  
LIMIT 5  
// 执行时间:11.0777 
 
//使用in,代码如下: 
SELECT * FROM article  
WHERE article_category IN (2,3)  
ORDER BY article_id DESC  
LIMIT 5 
 // 执行时间:11.2850 
 
//使用union all,代码如下: 
(  
SELECT * FROM article  
WHERE article_category=2  
ORDER BY article_id DESC  
LIMIT 5  
) UNION ALL (  
SELECT * FROM article  
WHERE article_category=3  
ORDER BY article_id DESC  
LIMIT 5  
)  
ORDER BY article_id DESC  
LIMIT 5  
// 执行时间:0.0261
Copy after login


教程链接:

随意转载~但请保留教程地址★

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template