数据无法以适当的方式获得我想要的PostgreSQL多个内部加入
我试图在两个桌子上进行内部连接。 1。用户,2。骑行。在用户表中有两种类型的用户(用户为0,驱动程序为1)。在骑行桌上,我存储了来自用户表的User_id和suff_id。因此,现在问题是我无法同时获得两个用户的信息。
SELECT name,mobile, email, name as driverName
FROM users
INNER JOIN rides
ON users._id = rides.user_id
INNER JOIN rides as ride
ON users._id = ride.provider_id;
这个返回我的桌子。
名称 | 号码 | 电子邮件 | 驱动器 |
---|
,当我只使用单个加入时:
SELECT name,mobile, email, name as driverName
FROM users
INNER JOIN rides
ON users._id = rides.user_id```
it return me name , mobile and email but not drivername.
| name | number | email |drivername |
|:---- |:------:| -----:|----------:|
| xyz | 000000 | email | |
i want ouput like this
| name | number | email |drivername |
|:---- |:------:| -----:|----------:|
| xyz | 000000 | email | abcsd |
i.m trying to do a inner join on two table. 1. users , 2. rides. in user table there are two types of user(0 for user , 1 for driver). and in ride table i store user_id and provide_id which came from users table. so now problem is that i can't get information of both user simultaneously.
SELECT name,mobile, email, name as driverName
FROM users
INNER JOIN rides
ON users._id = rides.user_id
INNER JOIN rides as ride
ON users._id = ride.provider_id;
this return me null table.
name | number | drivername |
---|
and when i use only single join :
SELECT name,mobile, email, name as driverName
FROM users
INNER JOIN rides
ON users._id = rides.user_id```
it return me name , mobile and email but not drivername.
| name | number | email |drivername |
|:---- |:------:| -----:|----------:|
| xyz | 000000 | email | |
i want ouput like this
| name | number | email |drivername |
|:---- |:------:| -----:|----------:|
| xyz | 000000 | email | abcsd |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能倾向于使用存在的逻辑来表达您的查询:
这将返回每个用户和提供商乘车的用户。
I might be inclined to express your query using exists logic:
This will return every user for whom there is a both a user and provider ride.