Jake Marmak Jake Marmak - 1 month ago 7
SQL Question

Consolidating two tables with repeating results

I am having a problem how to query two tables as shown

Table 1

id module
1 Part1
2 Part2
3 Part3
4 Part4


Table 2

id Town
1 Town 1
2 Town 2
3 Town 4


Resulting query

Module Town
Part1 Town 1
Part2 Town 1
Part3 Town 1
Part4 Town 1
Part1 Town 2
Part2 Town 2
Part3 Town 2
Part4 Town 2
Part1 Town 4
Part2 Town 4
Part3 Town 4
Part4 Town 4


I tried using union but got a different result. Hoping for your kind solution to this problem of mine...

Answer

When you want implement a cartesian product you must use CROSS JOIN statement

Try this:

SELECT table1.module, table2.town
FROM table1
CROSS JOIN table2

You can see here about JOINs operation in SQLite

Comments