I have the following query:
select *
FROM y,x
y has 3 tuples and x has 3 tuples.
Is the number of tuples returned by the query 9 since there is no condition?
I have the following query:
select *
FROM y,x
y has 3 tuples and x has 3 tuples.
Is the number of tuples returned by the query 9 since there is no condition?
And I'd like to add:
Since the early nineties, the ANSI standard for SQL offers the explicit join.
Instead of :
SELECT *
FROM x,y;
You should do it explicitly:
SELECT *
FROM x
CROSS JOIN x;
This way, you document that you don't just happen to join two tables without caring how, but you CROSS JOIN the two tables and know what you're doing.
Not necessary to delve into the topic why cross joins should be used with care ...
Good luck -
Marco the sane
A join links two tables and selects tuples by join type(left, right, full.) In your example it looks like you're looking for a function similar to this.
SELECT *
FROM X
JOIN Y
ON x.column_name=y.column_name;
You need to have a related field in each table to join them. The output would actually be 6 tuples.
They are simply the Cartesian products
Table A = {1,2}; Table B = {3,4}
Table A × Table B = {1,2} × {3,4} = {(1,3), (1,4), (2,3), (2,4)}
Table B × Table A = {3,4} × {1,2} = {(3,1), (3,2), (4,1), (4,2)}
http://www.sql-join.com/sql-join-types/
Also check What is the difference between Cartesian product and cross join?