如何检查关系是否存在 - 多对多关系
我需要你的帮助来弄清楚如何进行查询。 我的想法是建立一个信用体系来奖励用户。 管理员输入积分的描述(例如,用户订阅了时事通讯,他发布了至少 10 条评论......)。 我有 3 个表:
- 用户(id 和名称)、
- 奖励(id 和描述)、
- rewards_users(id_reward、id_user)。
我会拉出一个摘要 html 表,其行由用户名和 Y 或 N 组成,具体取决于用户和奖励之间是否存在关系。
I need your help to figure out how to make a query.
My idea was to build a credit system to reward users.
The administrator enters the description of credits (e.g., user is subscribed to the newsletter, he had post at least 10 comments...).
I have 3 tables:
- users (id and name),
- rewards (id and description),
- rewards_users (id_reward, id_user).
I would pull out a summary html table whose rows are formed by the user's name and a Y or an N depending on whether there is a relationship between the user and the reward.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用以下查询显示特定用户的所有奖励
,并将其用作子查询来获取用户详细信息,
例如:
注意:未经测试。
use the following query to show all of the rewards for a specific user
and use it as a sub query to get the users details too
e.g:
Note: not tested.
在我看来,您需要在用户表和rewards_users表之间进行左连接,然后处理空rewards_id的实例:
Sounds to me like you need a LEFT JOIN between your users table and the rewards_users table and then to handle instances of null rewards_id: