3
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

6

This is called a cartesian product or a CROSS JOIN:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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