我有 2 個包含大量列的表(每個表都有大約 700-800 列,這使得單獨撰寫所有列名不可行)。這兩個表都有一些共同的行。我需要動態合并兩個表,以便公共列不會重復并且在最終表中只查詢一次。例如:
TABLE 1:
--------- -------- ------ -------
|firstname|lastname|upload|product|
--------- -------- ------ -------
| alice| a| 100|apple |
| bob| b| 23|orange |
--------- -------- ------ -------
表 2:
--------- -------- ------ -------
|firstname|lastname|books |active |
--------- -------- ------ -------
| alice| a| 10 |yes |
| bob| b| 2 |no |
--------- -------- ------ -------
決賽桌:
--------- -------- ------ ------- ----- ------
|firstname|lastname|upload|product|books|active|
--------- -------- ------ ------- ----- ------
| alice| a| 100|apple | 10 | yes |
| bob| b| 23|orange | 2 | no |
--------- -------- ------ ------- ----- ------
uj5u.com熱心網友回復:
只為給你一個研究方向
select *
from table1
join table2
using(firstname, lastname)
如果應用于您問題中的樣本資料 - 輸出是

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/449609.html
上一篇:連接兩個表并對兩者中的列求和
