I have a table than contains 100 rows. I want to select 200 items from it, using random rows to generate more results than the table has rows for:
SELECT * FROM `rows` ORDER BY RANDOM() LIMIT 200;
This query predictably returns 100 results. Is there a way to randomly select more than is actually contained in the table?
EDIT
Is there a way to select an arbitrary number of records without adding compounding join
statements? For example, what if the requested count (LIMIT
) of items is unknown in advance or is arbitrarily large?
If you want to insert more rows than that, you should consider using multiple INSERT statements, BULK INSERT or a derived table. Note that this INSERT multiple rows syntax is only supported in SQL Server 2008 or later. To insert multiple rows returned from a SELECT statement, you use the INSERT INTO SELECT statement.
Selecting rows with SQL statements. Selecting rows limits, or creates a subset of, the data in a table. You select rows by creating a row condition. Selecting rows that have no data. You can select rows that have no data in a column.
To select last two rows, use ORDER BY DESC LIMIT 2.
try something like this
SELECT *
FROM `rows`
cross join `rows`
ORDER BY RANDOM()
LIMIT 200;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With