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.