2016-06-12 157 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

感谢,认为工程:) –