MYSQL 嵌套查询有两个 select
MYSQL Nested Query with two select
我有:
Table1 (UserID -City - Adress - Mobile)
Table2 (DeviceID - UserID - Vendor - Model).
我想对 select 一行中的以下内容执行嵌套查询:
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)
如何在同一查询中执行第二个 select 以在模型之后的同一行中打印。
使用内部 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
我有:
Table1 (UserID -City - Adress - Mobile)
Table2 (DeviceID - UserID - Vendor - Model).
我想对 select 一行中的以下内容执行嵌套查询:
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)
如何在同一查询中执行第二个 select 以在模型之后的同一行中打印。
使用内部 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