不幸的是我不像SQL那么好,而且我试图在三个表之间完成连接。
这是一个粗略的简化表结构:
links: id, url, description categories: id, name, path link_cat: link_id, cat_id我瞄准的选择语句应该有
links.id, link.url, link.description, categories.name, categories.path通过link_cat表匹配链接和类别的位置。 我认为只要每个链接只有一个类别,就不应该太难。 这就是我所假设的。 如果不是,那么将另一种将多个类别逗号分隔为categories.name字段的方法会更好。
我希望这一切都是可以理解的,听起来并不太愚蠢。
unfortunately i'm not that good as SQL and i'm trying to get a join between three tables done.
here's a rough simplified table structure:
links: id, url, description categories: id, name, path link_cat: link_id, cat_idThe select statement I'm aiming for should have
links.id, link.url, link.description, categories.name, categories.pathWhere links and categories are matched via the link_cat table. I think that shouldn't be too hard as long as there's only one category for each link. This is what I'm assuming. If not it would be good to have another way that pulls multiple categories comma separated into the categories.name field.
I hope this is all understandable and doesn't sound too silly.
最满意答案
SELECT links.id, links.url, links.description, categories.name, categories.path FROM links INNER JOIN link_cat ON links.id = link_cat.links_id INNER JOIN categories ON categories.id = link_cat.category_id SELECT links.id, links.url, links.description, categories.name, categories.path FROM links INNER JOIN link_cat ON links.id = link_cat.links_id INNER JOIN categories ON categories.id = link_cat.category_id更多推荐
发布评论