Sheriff Said Elahl Sheriff Said Elahl - 5 months ago 23
MySQL Question

MYSQL Nested Query with two select

I have:

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


I want to perform nested query to select the following in one row:

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)


How can I perfom the second select in the same query to be printed in the same row after Model.

Answer

Use 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