Search code examples
sqlsql-serverdatabaseresultset

Select every record in SQL


Is there any easy way to select every record for two tables, kind of hard to explain but if I have two tables Client and Product

Client
A
B
C

Product
1
2
3

What query would get a result like this:

RESULT
A1
A2
A3
B1
B2
B3
C1
C2
C3

Solution

  • That's called a cross join (or a cartesian product):

    select c.field, p.field
    from client c 
        cross join product p
    

    It's fairly straight-forward to combine the columns together at this point.