There are three tables:
User table: user-------------------user_id
Article table: article----------------article_id,user_id;
Comment form: article_comment----comment_id,article_id
The user table has a one-to-many-to-many relationship with the article_comment table.
Now, article_comment is divided into tables. According to article_id%6, it is divided into six tables article_comment_0/1/2/3/4/5.
Now we need to display the comments of all articles of a certain user according to the time of the comment. How to use SQL What about writing?
There are three tables:
User table: user-------------------user_id
Article table: article----------------article_id,user_id;
Comment form: article_comment----comment_id,article_id
The user table has a one-to-many-to-many relationship with the article_comment table.
Now the article_comment is divided into tables. According to article_id%6, it is divided into six tables article_comment_0/1/2/3/4/5.
Now we need to display the comments of all articles of a certain user according to the time of the comment. How to use SQL What about writing?
<code>SELECT * FROM((SELECT * FROM article_comment_0 INNER JOIN article ON article_comment_0.article_id=article.article_id WHERE article.user_id='userid') UNION (SELECT * FROM article_comment_1 INNER JOIN article ON article_comment_1.article_id=article.article_id WHERE article.user_id='userid') UNION (SELECT * FROM article_comment_2 INNER JOIN article ON article_comment_2.article_id=article.article_id WHERE article.user_id='userid') UNION (SELECT * FROM article_comment_3 INNER JOIN article ON article_comment_3.article_id=article.article_id WHERE article.user_id='userid') UNION (SELECT * FROM article_comment_4 INNER JOIN article ON article_comment_4.article_id=article.article_id WHERE article.user_id='userid') UNION (SELECT * FROM article_comment_5 INNER JOIN article ON article_comment_5.article_id=article.article_id WHERE article.user_id='userid')) res ORDER BY res.comment_createtime DESC </code>
If your table is designed like this, you need to connect the article query every time, so it is recommended to add a redundant user_id field in the common table, so that the query does not require one more step
If you can do it without splitting the tables, don’t split the tables. Split tables will bring a lot of trouble to development. You can use partitions. I don’t know much about mysql, but I found this:
http://dev.mysql.com/doc/refm...
The table should be divided according to your query conditions, otherwise there is no good way