My database table has 15 records and I want to show 9 at random on screen.
SELECT * FROM tablename ORDER BY RAND() LIMIT 9
This works as expected, but what if the table only has 9 records? I need to pull 15 random records.
I understand this will duplicate one or more records, but that’s my intention.
Your
selectwill only pull the number of records in the table regardless of theorder by. You can use various means to duplicate the table data, however, before you order them. For example,union allof the rows together twice: