search

Home  >  Q&A  >  body text

mysql - 博客文章标签表结构设计问题

感觉segmentfault站点设计的标签还是很不错的,正在写一个博客平台,想做个文章标签,现在表设计如下:

文章表(articles)

id title tags
1 xxx 1,3,4
2 aaa 2,4
3 bbb 3,5

标签表(tags)

id name
1 php
2 javascript
3 mysql
4 css3
5 html5

假如信息结构如上面,那么怎么取出每篇文章的详细信息呢?上面的表设计可以实现吗?

我查了下本站的相关问题,有人说再加入第三章标签文章关联表,如下面

标签关联表(tag_links) tidtagsid,aid是文章articlesid

id tid aid
1 1 1
2 3 1
2 4 1

那么这个有怎么查出文章的详细信息呢?

天蓬老师天蓬老师2767 days ago448

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-17 15:57:13

    Generally, the table is built in the following way. If you want to query detailed information, you can first check some information about the article in the article table based on the article ID, and then use the article ID to join the tag table and the article tag association table to query. Label data, finally merge these two arrays.

    A little suggestion: You can split the article table horizontally, you can take out the content fields and make a separate table, and use ID to key. This is more efficient when the amount of data is large,

    These are my personal opinions. If there is something wrong, I hope the experts can point me out

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 15:57:13

    I happen to be writing a blog, and I also encountered this problem, 3 tables are related, and now I have a problem with the sql statement
    Please give me the Sql statement

    reply
    0
  • Cancelreply