Home > database >  SQL how to split the two table data, forming a many-to-many relationship?
SQL how to split the two table data, forming a many-to-many relationship?

Time:01-31

With SQL, how can we split the data from table 1 and table 2, the formation of table 3

Table 1
The customer name amount
A. invoice 1 2340
A. invoice 2 4680
A. invoice in 3 1170
A. invoice 4 2340
A. invoice 5 11700
A. invoice 6 2870
1 B invoice 2340
B the invoice 2 4680
B the invoice 3 1170
4 B invoice 2340
B the invoice 5 11700


Table 2
The customer name amount
A voucher 1 100
A receipt for 2 3000
A receipt for 3 5000
A voucher 4 7000
A receipt for 5 10000
B voucher 1 100
B voucher 2 3000
B voucher 3 5000
B voucher 4 7000


Table 3
Customer name 1 amount 2
A. invoice 100 of voucher 1
A. invoice 1 2240 voucher 2
A. invoice 2 760 voucher 2
A. invoice 2 3920 voucher 3
A. invoice in 3 1080 voucher 3
A. invoice in 3 90 voucher 4
A. invoice 4 2340 voucher 4
A. invoice 5 4570 voucher 4
A. invoice 5 7130 voucher
A. invoice 6 2870 voucher
B. invoice 100 of voucher 1
B. invoice 1 2240 voucher 2
Invoice 760 of voucher 2 B
Invoice 2 3920 voucher 3 B
Invoice 3 1080 voucher 3 B
B. invoice 3 90 voucher 4
B. invoice 4 2340 voucher 4
B the invoice 5 4570 voucher 4




  • Related