Search code examples
sqletldata-analysis

One record from one table to show up on all records on another table


I have two tables. Table A and B. Table A would have data like:

    +---+---+---+
    | a | b | c |
    +---+---+---+
    | 2 | 1 | 8 |
    | 3 | 6 | 7 |
    | 4 | 5 | 9 |
    +---+---+---+

And table B as:

    +----+----+
    | e  | f  |
    +----+----+
    | 11 | 14 |
    +----+----+

I want to create a SQL query that would provide me an output where I keep all the records from table A and only the one record from table B, but the values from that one record in each column from table B would show up in all the records in table A. The result of the data set would look kike this:

    +---+---+---+----+----+
    | a | b | c | e  | f  |
    +---+---+---+----+----+
    | 2 | 1 | 8 | 11 | 14 |
    | 3 | 6 | 7 | 11 | 14 |
    | 4 | 5 | 9 | 11 | 14 |
    +---+---+---+----+----+

I am not sure how SQL handles appending records like this on table result. I would assume that there is a way to call out those fields from table B and do some kind of union to table A? If there is another question that has the answer then please flag this question as answered. Thank you.


Solution

  • You coudl try using a cross join

    select a, b, c, d, f
    from A
    cross join B