>  기사  >  백엔드 개발  >  SQL语句这样的写法是否存在有关问题

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

WBOY
WBOY원래의
2016-06-13 10:38:11817검색

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>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.