Click to See Complete Forum and Search --> : Simple SQL


Albatross
April 21st, 2003, 05:29 AM
Something basic :
I have two tables tbl1 and tbl2 in a mysql database.

The first table has three records X, Y, Z
and the the second table has two records A and B

They have no common fields ( foreign keys )

With an SQL statement I'd like to generate a list of six records looking like this :

X A
X B
Y A
Y B
Z A
Z B

(Sequence is not important)
There is some basic function to do this which I can't recall at the moment.
I have a suspicion that it is only possible in Oracle with the sub-select
statements ( = select f1 from tblx where f2 = (select f3 from tbly) ; )
Can you help me on this?

M Owen
April 21st, 2003, 11:36 AM
Not really possible ... You can either of the sets with a Left or Right Outer Join ...

Albatross
April 22nd, 2003, 04:16 AM
found it,
to show a list of 6 elements from a table of 3 and a table of 2 one writes :

select * from tbl1, tbl2;

that outer/inner join stuff I'll try too.

Thread1
May 8th, 2003, 05:06 AM
Another join term for this is called CROSS JOIN

SELECT * FROM T1 CROSS JOIN T2