rockingrock
rockingrock

Reputation: 27

Why a SELECT result is repeated 4 times?

I have these tables:

Table 1

Table 2

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

Answers (1)

Gordon Linoff
Gordon Linoff

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

Related Questions