'Results of join listed in rows vs additional columns?

I have 2 tables, with the same exact fields and fields names. i am trying to inner join them but im having some difficulty determining how i can get my results in my desired format.

I know i can do select a.customer, a.id, a.date, a.line, a.product, b.customer, b.id, b.date, b.line, b.product but instead of having my A data and B data on the same row, id like for them to be on seperate rows.

I have 2 tables, with the same exact fields and fields names, i am trying to inner join them so that unique line becomes a row.

Table A: |customer| id | Date | line | Product| |--------|-----|---------|------|--------| | 445678 | 123 | 1/1/22 | 10 | 88975 | | 853652 | 456 | 1/10/22 | 5 | 55876 | | 845689 | 789 | 1/25/22 | 1 | 45587 |

TABLE B: |customer| id | Date | line | Product| |--------|-----|---------|------|--------| | 445678 | 489 | 1/1/22 | 1 | 87574 | | 853652 | 853 | 1/10/22 | 12 | 45678 | | 587435 | 157 | 2/12/22 | 3 | 25896 |

DESIRED RESULTS: |customer| id | Date | line | Product| |--------|-----|---------|------|--------| | 445678 | 123 | 1/1/22 | 10 | 88975 | | 445678 | 489 | 1/1/22 | 1 | 87574 | | 853652 | 456 | 1/10/22 | 5 | 55876 | | 853652 | 853 | 1/10/22 | 12 | 45678 |

my query: select a.customer, a.id, a.date, a.line, a.product from data1 a inner join data2 b on a.date = b.date and a.customer = b.customer



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source