Mysql 5个表之间的连接问题
抱歉我的英语不好,我来自奥地利,但我找不到另一个不错的问答板。 :)
我有一个非常奇怪的结构化 mysql 数据库。 首先有一个用户表,对于我的示例,只有三列有趣:
id, name, email
- 我的第二个表是事件表:id、name
- 我的第三个表是事件的类别表:id、name、eventID
- 我的第四个表是事件的下类别表:id,name,catID
- 我的第五个表是事件的时间表:id,name,ucatID
- 我的第六个表是一个表,其中一个条目将时间与人结合起来
它是工作计划,在某种程度上...
- 用户:id,名称,电子邮件
- 事件:id,名称
- 类别:id,名称,eventID
- 下类别:id,名称,catID
- 下类别:id,名称,ucatID
- 要加入的表:id,userID,uucatID
是的,到目前为止,每个条目 (用户名, ucat-name, uucat-name)
... 但我正在尝试获取在连接表中没有条目的人员列表! (但仅限于 eventID 为...例如 1^^)
这是我的列表代码,其中有一个条目:
SELECT a.*,b.name,c.name AS zeit,d.name AS kategorie
FROM intern_user AS b
INNER JOIN intern_dienstplan AS a ON a.userID=b.id
INNER JOIN intern_events_uucat AS c ON a.uucatID=c.id
INNER JOIN intern_events_ucat AS d ON c.ucatID=d.id
INNER JOIN intern_events_cat AS e ON d.catID=e.id
WHERE e.eventID='".$_POST['eventid']."'
ORDER BY b.name ASC
我希望有人可以帮助我...我已经尝试过使用“a.id is null” “(连接表中没有条目),但它不起作用。
Sorry for my english, I'm from austria, but I couldn't find another nice q&a-board. :)
I have a very strange structured mysql-database.
First there is a table for users, for my example there are only three colums interesting:
id, name, email
- My second table is a table for events: id, name
- My third table is a category-table for events: id, name, eventID
- My fourth table is a undercategory-table for events: id, name, catID
- My fifth table is a time-table for events: id, name, ucatID
- My sixth table is a table, where a entry combines a time with a person
Its a plan for work, in some way...
- users: id, name, email
- events: id, name
- categories: id, name, eventID
- undercategories: id, name, catID
- underundercategories: id, name, ucatID
- table to join: id, userID, uucatID
Yeah I have, so far, every entry (user-name, ucat-name, uucat-name)
...
but I'm trying to get a list of persons who have no entry in the join-table! (but only, where the eventID is ... say 1^^)
Here is my code for the list where there is an entry:
SELECT a.*,b.name,c.name AS zeit,d.name AS kategorie
FROM intern_user AS b
INNER JOIN intern_dienstplan AS a ON a.userID=b.id
INNER JOIN intern_events_uucat AS c ON a.uucatID=c.id
INNER JOIN intern_events_ucat AS d ON c.ucatID=d.id
INNER JOIN intern_events_cat AS e ON d.catID=e.id
WHERE e.eventID='".$_POST['eventid']."'
ORDER BY b.name ASC
I hope someone can help me... I have already tried something with "a.id is null" (where is no entry in join-table), but it doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很长一段时间过去了......我已经找到了解决我的问题的方法。 :]
这里是代码,供其他有同样问题的人使用...
感谢所有帮助,祝你玩得开心。 :D
问候
A long time has gone... and I have found the solution for my problem. :]
Here the code, for others with the same problem...
Thanks for all help and have fun with this shit. :D
Greets
目前尚不清楚类别-子类别-子子类别的连接类型是什么。
有多少子类别可以有该事件 (0-1-N)?
如果你只是想查找链接表中没有匹配记录的人,你可以使用查询:
或
更新。上述问题仍然没有答案。
你可以尝试:
它可以很容易地转换为带有 left join 或 contains() 的版本。
It's not clear what is type of connection for categories-subcategories-subsubcategories.
How much subcategories could have the event (0-1-N)?
If you just want to find persons who do not have matched record in link table, you can use a query:
or
Update. Still do not have answer for the question above.
You can try:
It could be easy transformed to versions with left join or exists().