9
table 1
|id|name  |
------------
|1 |Bob   |
|2 |Frank |
|3 |Paula |

Table 2
|id|item|
---------
|1 |a   |
|2 |b   |
|3 |c   |

i need to write a query to show me all the combinations of the two tables as below:

result
|name|item|
-----------
|bob |a   |
|bob |b   |
|bob |c   |
etc

I am currently using mysql any help would be greatly appreciated

0

1 Answer 1

14

This is called a cartesian product or a CROSS JOIN:

SELECT 
    a.name,  b.item 
FROM 
    table1 AS a 
  CROSS JOIN 
    table2 AS b;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.