Home  >  Article  >  Backend Development  >  SQL语句这样的写法是否存在有关问题

SQL语句这样的写法是否存在有关问题

WBOY
WBOYOriginal
2016-06-13 10:38:11813browse

SQL语句这样的写法是否存在问题
select * from (select * from xf_art where flag=3 order by add_time desc) a,(select id userid,username from xf_usr where flag!=9 ) u where a.xfuid=u.userid order by a.add_time desc
 
以上的sql语句是我一个已离职的同事写,运行正常,但是怎么看都觉得有点别扭,SQL语句这样的写法是否存在问题呢?问题再在哪里(我现在也说不出来,所以请教各位了)

------解决方案--------------------
语句没问题,效率可能有些问题,用explain查一下。

SQL code
explain select * from (select * from xf_art where flag=3 order by add_time desc) a,(select id userid,username from xf_usr where flag!=9 ) u where a.xfuid=u.userid order by a.add_time desc<br><font color="#e78608">------解决方案--------------------</font><br>没有问题,从性能来看,第一个order by add_time desc可以不需要。<br><font color="#e78608">------解决方案--------------------</font><br>这样的sql语句没问题 是可以运行的 但是执行的效率还要进一步的修改了。<br><br>他就是  select * from 表a ,   表u  where a.xfuid=u.userid;<br>a 是个表 这个表不是数据库现有的 而是通过某种条件查询出的表。<div class="clear">
                 
              
              
        
            </div>
Statement:
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