How can a sql statement find specified data and random data?

scenario: there are 100 pieces of data in the data table, and each piece of data has n fields. In general, on the list page, you only need to load 5 items at a time according to the id order of the table. Now I want to query not only 5 pieces of data in order, but also one other piece of data randomly, and return the results to the front end

.

question: how to find out the result of 5: 1 at one time (a sql statement)?

Sep.16,2021

you can do this in MySQL

(SELECT * FROM table limit 5)
UNION
(SELECT * FROM table order by rand() limit 1)

I can't think of a good idea. Here's just a reference

SELECT * FROM table WHERE id IN (6,7,8,9,10,n);

n is the ID of that random data


refer to the following

SQL UNION Operator
Menu