简体   繁体   中英

SQL Nested /Sub-query and SQL produce the same result. Why using Nested/Sub-Query?

I don't understand why the solution gives me a nested solution when I can get the same result with non-nested SQL stmt. Is it better to use Nested SQL ? Thanks !

Here is the code :

SQL :

select EMP_ID, F_NAME, L_NAME, DEP_ID from employees;

SQL Nested/Sub-Query solution :

select * from ( select EMP_ID, F_NAME, L_NAME, DEP_ID from employees) AS EMP4ALL;

The query optimser of whichever platform you use will almost certainly parse these to be identical and produce the same execution plan for each.

In short, they are the same; the derived table query may be a cut-down version of something more complex and the author just chose to leave it that way, unknown really without more context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM