Dear God, now I have a difficult problem that needs your help.
There are two of the following tables
Post table: Article table.
Record table: A table of records used to record the user's reading order.
The record table records the primary key ID of the post table with a field PostID, based on the user's reading order, and the Record.postid foreign key is post.id.
Now you need to find the Post table article based on the PostID in the record table. (assuming that the reading order is: ' Article 1, article 2, article 2, article 3, Article 3 ' allows the article to repeat. )
I started with
SELECT *FROM postWHERE id IN (postid1,postid2,postid2,postid3,postid3);
Finding results can only look for postid1,postid2,postid3 articles.
The business logic you want now is:
1: Find post table articles based on user's reading history.
2: Allow repetition.
For example, users read the article reading order is: ' Article 1, article 2, article 2, article 3, Article 3 ', look for the post table results are: POST.ID1, post.id2,post.id2,post.id2,post.id3.
Note: Consider using a For loop
for (.....){ ... 变量 数组x; 数组x添加 SELECT * FROM post WHERE id = postidx; .... }
But they worry about efficiency.
Reply content:
Dear God, now I have a difficult problem that needs your help.
There are two of the following tables
Post table: Article table.
Record table: A table of records used to record the user's reading order.
The record table records the primary key ID of the post table with a field PostID, based on the user's reading order, and the Record.postid foreign key is post.id.
Now you need to find the Post table article based on the PostID in the record table. (assuming that the reading order is: ' Article 1, article 2, article 2, article 3, Article 3 ' allows the article to repeat. )
I started with
SELECT *FROM postWHERE id IN (postid1,postid2,postid2,postid3,postid3);
Finding results can only look for postid1,postid2,postid3 articles.
The business logic you want now is:
1: Find post table articles based on user's reading history.
2: Allow repetition.
For example, users read the article reading order is: ' Article 1, article 2, article 2, article 3, Article 3 ', look for the post table results are: POST.ID1, post.id2,post.id2,post.id2,post.id3.
Note: Consider using a For loop
for (.....){ ... 变量 数组x; 数组x添加 SELECT * FROM post WHERE id = postidx; .... }
But they worry about efficiency.
SELECT p.*
From Post P
Left JOIN Record R on r.postid = p.id
ORDER by R.id ASC
The record table records the reading order, so it needs to be sorted according to the order of the record table
can provide a way of thinking: using in to extract data from the database, map to establish a corresponding relationship map.put (postid,post). The data types required for assembly are then taken out in the order of the IDs