MYSQL嵌套查询有两个选择

时间:2016-06-12 12:22:57

标签: mysql nested-queries

我有:

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)

如何在同一个查询中执行第二个选择,以便在Model之后打印在同一行中。

1 个答案:

答案 0 :(得分:1)

使用内部联接

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