MySQL:从多个表中检索数据 [英] MySQL: Retrieve data from multiple tables
问题描述
我需要从 如何在SQL代码中执行此操作? 使用INNER JOIN尝试以下查询。 Please have a look at the below table structure. I need to retrieve all the fields from the How can I do this in SQL Code? Try following query with INNER JOIN.
这篇关于MySQL:从多个表中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!外键 code>对于
提供者
表,它不是 NULL
。对于客户端
表,外键
这也不是 NULL
。
Portfolio
表中检索所有字段, Client 和
提供者
分配给客户端
的名称,由 Portfolio
表..
SELECT Portfolio。*, Client.name作为Client Name,Provider.name作为Provider Name
FROM Portfolio
INNER JOIN Client ON Portfolio.Client_id = Client.id
INNER JOIN Provider ON Client.Provider_id = Provider.id
Client
table has the foreign key
for Provider
Table, which is not NULL
. Portfolio
table has the foreign key
for the Client
table, which is also not NULL
. Portfolio
table, Name of the Client
and the Provider
Name who is allocated to the Client
which is referred by the Portfolio
table..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