2016-06-12 215 views
0

我:MYSQL嵌套查詢有兩個選擇

Table1 (UserID -City - Adress - Mobile) 
Table2 (DeviceID - UserID - Vendor - Model). 

我想執行嵌套查詢選擇一行如下:

select DeviceID, UserID, Model From Table2 Where Vendor=Sony 
(and for this row go and select City - Address - Mobile from table 1 where table1.UserID = Table2.UserID) 

我怎樣才能perfom第二選擇在同一模型後查詢要打印在同一行中。

回答

1

使用INNER JOIN

select 
     t2.DeviceID 
    , t2.UserID 
    , t2.Model 
    , t1.city 
    , t1.Address 
    , ti.mobile 
From Table2 as t2 
Where Vendor='Sony' 
INNER JOIN table1 as t1 on t1.UserID = t2.UserID 
+0

感謝,認爲工程:) –