Skip to content Skip to sidebar Skip to footer

MySQL: Retrieve Data From Multiple Tables

Please have a look at the below table structure. Client table has the foreign key for Provider Table, which is not NULL. Portfolio table has the foreign key for the Client table,

Solution 1:

Try following query with INNER JOIN.

SELECT Portfolio.*,Client.name as "Client Name",Provider.name as "Provider Name"
FROM Portfolio
INNER JOIN Client ON Portfolio.Client_id=Client.id
INNER JOIN Provider ON Client.Provider_id = Provider.id

Solution 2:

This should give you the result you expected:

Select * from client 
  join portfolio on client.id=portfolio.clientId
  join provider on client.provider_id=provider.id

Post a Comment for "MySQL: Retrieve Data From Multiple Tables"