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
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e7c1-4f07f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e7c1-4f07f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?