Sheriff Said Elahl
Sheriff Said Elahl

Reputation: 177

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.

Upvotes: 0

Views: 37

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

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

Upvotes: 1

Related Questions