Dear friends, I have encountered a difficult problem and need your help. There are two post tables: article table. Record table: a record table used to record the reading sequence of users. The record table uses a postid field to record the primary key ID of the post table based on the user's reading order, both record. p.
There are two tables below
Post table: document table.
Record table: a record table used to record the reading sequence of users.
The record table uses a postid field to record the primary key ID of the post table based on the user's reading order. the foreign key of record. postid is post. id.
Now you need to search for post table articles based on postid in the record table. (Assume that the reading sequence is: 'Article 1, Article 2, Article 2, Article 3, and article 3 .)
Start using
SELECT *FROM postWHERE id IN (postid1,postid2,postid2,postid3,postid3);
You can only search for postid1, postid2, and postid3.
The business logic is as follows:
1: Search for post table articles based on the user's reading records.
2: repeat is allowed.
For example, if the reading sequence of an article is 'Article 1, Article 2, Article 2, Article 3, Article 3', the result of searching for the post table is: post. id1, post. id2, post. id2, post. id2, post. id3.
Note: We have considered using the FOR loop.
For (...) {variable array x; array x add SELECT * FROM post WHERE id = postidx ;....}
However, they are worried about efficiency.
Reply content:
Dear friends, I have encountered a difficult problem and need your help.
There are two tables below
Post table: document table.
Record table: a record table used to record the reading sequence of users.
The record table uses a postid field to record the primary key ID of the post table based on the user's reading order. the foreign key of record. postid is post. id.
Now you need to search for post table articles based on postid in the record table. (Assume that the reading sequence is: 'Article 1, Article 2, Article 2, Article 3, and article 3 .)
Start using
SELECT *FROM postWHERE id IN (postid1,postid2,postid2,postid3,postid3);
You can only search for postid1, postid2, and postid3.
The business logic is as follows:
1: Search for post table articles based on the user's reading records.
2: repeat is allowed.
For example, if the reading sequence of an article is 'Article 1, Article 2, Article 2, Article 3, Article 3', the result of searching for the post table is: post. id1, post. id2, post. id2, post. id2, post. id3.
Note: We have considered using the FOR loop.
For (...) {variable array x; array x add SELECT * FROM post WHERE id = postidx ;....}
However, they are worried about efficiency.
Select p .*
FROM Post P
Left join Record r on r. PostID = P. ID
Order by r. ID ASC
The reading sequence of records in the Record table. Therefore, you need to sort the records in the order of the Record table.
One idea can be provided: extract data from the database using the in method, and use map to establish the corresponding map. put (postid, post ). Then the data types are assembled in the order of IDs.