Is there any problem with writing SQL statements?

Source: Internet
Author: User
Is there a problem with writing SQL statements like this: select * from (select * fromxf_artwhereflag3orderbyadd_timedesc) a, (selectiduserid, usernamefromxf_usrwhereflag! 9) Is there a problem with writing uwherea. xfuidu. useridorder SQL statements?
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

The preceding SQL statements are written by a former employee and run normally. However, they all seem awkward. Is there a problem with writing SQL statements? Where can I find the problem? (I can't say it now, so I 'd like to ask you)

------ Solution --------------------
The statement is correct, and the efficiency may be faulty. use explain to check it.
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
------ Solution --------------------
No problem. in terms of performance, the first order by add_time desc is not required.
------ Solution --------------------
Such SQL statements can be run, but the execution efficiency must be further modified.

This is select * from Table a, table u where a. xfuid = u. userid;
A is a table. This table is not existing in the database, but is queried by certain conditions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.