2017-03-07 103 views
0

我開始使用MySQL,我不知道如何解決這樣的事情:MySQL的聯合選取表1字段3 =表2字段5

SELECT 
    table1.col1 AS A, 
    table1.col3 As B 
UNION 
    table2.col2 AS C, 
    table2.col5 AS D 
WHERE 
    table1.col4 = table2.col6 

/*expected*/ 
A B C D 

回答

1

爲什麼不直接說:

SELECT 
    table1.col1 AS A, 
    table1.col3 As B, 
    table2.col2 AS C, 
    table2.col5 AS D 
FROM TABLE1 
INNER JOIN Table2 on TABLE2.col6=TABLE1.col4 
相關問題