Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between queries please 1

Status
Not open for further replies.

kishorecvr

Programmer
Feb 21, 2002
19
0
0
IN
Can any one give me the difference between the following queries please....

SELECT * FROM employee
WHERE department_id = 30 AND salary < 2850;

SELECT * FROM employee
WHERE salary IN
(SELECT salary FROM employee
WHERE department_id = 30 AND salary < 2850);
 
I would say that your first query does the job you want.
The second one does the same but is unlikely complicated and should not ne used.

But if anyone has another opinion about this... let me hear.
Perhaps I am wrong.

cya

frag patrick.metz@epost.de
 
I agree the 2nd query is pointlessly complicated and will probably run slower unless the DBMS you are using has an unusually smart query optimizer/
 
The second one is completely different.
The first query is constrained to employees in Department 30.
The second query will return records for any employee in the company (regardless of department) that makes the same salary as any employee in Department 30 who is paid less than 2850.

If the second one said &quot;where empno in&quot; instead of &quot;where salary in&quot;, the queries would return the same information.
 
You are absolutly correct, that what I get for answering questions before my 1st cup of coffee. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top