连接多个行/列MySQL [英] Join multiple row/column MySQL

查看:95
本文介绍了连接多个行/列MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试与数据库做一些不同的事情,我得到了一个名为服务"的表,该表由pID,uID,serviceID组成.

Trying to do things a bit different with a database, I got a table called "services", this table consist off pID, uID, serviceID.

然后我得到了一个名为"user_profile"的表,该表当然具有与表服务中使用的相同的uID.

Then I got a table called "user_profile", that of course got the same uID as used in the table services.

例如,一个用户可以拥有多种服务

So a user can have multiple services, let's say

pID     uID     serviceID
1       1       101
2       1       102
3       1       104
4       2       105

那我该如何将它加入到我的user_profile数据中?我对此有些困惑.

So how do I join this to my user_profile data? I'm a bit confused about that.

假设某人访问了具有uID 1的个人资料.

Let's say somebody visits the profile with uID 1.

然后,如果可能的话,我需要在同一SQL调用中提供所有服务?

Then I need all the services to in the same SQL call if that's possible somehow?

希望我有一点道理.

推荐答案

要在SQL中关联表,必须在示例uID中在两个表中都包含同一列. 然后,您编写如下内容: 从user_profile中选择a.uID,b.pID,b.serviceID.a.uID = b.uID上的左加入服务b

In order to relate tables in SQL you must have in both tables the same column, in your example uID. Then you write something like: select a.uID,b.pID,b.serviceID from user_profile a left join services b on a.uID=b.uID

这篇关于连接多个行/列MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆