|
|
|
|
|
|
| Re: Subquery with multiple rows [message #637548 is a reply to message #637541] |
Wed, 20 May 2015 01:00  |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Hi,
aruntutor wrote on Wed, 20 May 2015 05:50in below query, am getting duplicate rows in the result, whereas not suppose to be. 
Based on what? Making your own SQL rules instead of the described e.g. in SQL Language Reference?
aruntutor wrote on Wed, 20 May 2015 05:50not able to find root cause for it. Kindly help me in finding out the root cause.
The root cause is not understanding basic principles of SQL language.
The inner query is aggregate one, so it returns one row per aggregate column/expression(s).
One or more rows in the input make one row in the output.
The outer one is non-aggregate query on one table/view - it returns each row from that table/view which satisfies its condition.
One row in the input make one row in the output.
One magic: what about this query: select department_id from employees;
? It also returns "duplicates" - as many rows with the same DEPARTMENT_ID as many employees are there. If it should not, what would be the use of GROUP BY clause then?
aruntutor wrote on Wed, 20 May 2015 05:50--Display employees getting min salary in each department.
What about displaying something which uniquely identifies each employee? There may be (and are) multiple ones in the same department with the same salary.
|
|
|
|