Reputation: 31
Basic question: How do I join 2 tables to get the following output?
Table1:
"type"
red
blue
big
small
===
Table2:
"object"
cat
person
chair
===
Output:
red cat
blue cat
big cat
small cat
red person
blue person
big person
small person
red chair
blue chair
big chair
small chair
Upvotes: 2
Views: 2098
Reputation: 108380
SELECT CONCAT(t1.type,' ',t2.object) as `Output:`
FROM table1 t1 CROSS JOIN table2 t2
(The keyword CROSS
is optional in mysql, but it does serve to document that you intended a cartesian product, which can be useful information for the person who reads this statement, who would normally be expecting to see a join predicate.
If you need the result set returned in a particular order, include an ORDER BY
clause. It's a relatively complicated expression to get it sorted in the order shown, but it can be done.
Upvotes: 3
Reputation: 21522
Cartesian product I guess:
SELECT t1.type, t2.object FROM Table1 t1, Table2 t2
Upvotes: 1