Reputation: 27
I have these tables:
When i try to make a select between them getting the APELLIDO
column:
SELECT APELLIDO FROM EMP, DEPT WHERE (EMP.DEPT_NO = 30);
it shows the correct information but it´s repeated 4 times!!! Why is this happening? Isn´t it correct? Another fact is that if i use this other sentence
SELECT APELLIDO FROM EMP WHERE DEPT_NO IN (SELECT DEPT_NO FROM DEPT WHERE DEPT_NO = 30);
it´s displayed correctly but why does the other command make that? Thank you.
Upvotes: 0
Views: 217
Reputation: 1270401
Never use commas in the FROM
clause. Always use proper, explicit, standard JOIN
syntax:.
However in your case, you don't even need a JOIN
. All the information is in EMP
:
SELECT EMP.APELLIDO
FROM EMP
WHERE EMP.DEPT_NO = 30;
The ,
operator does a CROSS JOIN
-- a full Cartesian product. There is no reason to do this for these two tables.
Upvotes: 1