Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to select more rows than a table contains?

Tags:

sql

sqlite

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?

like image 788
Arman H Avatar asked Aug 28 '13 08:08

Arman H


People also ask

How do I get more than one record in SQL?

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.

What is select row in SQL?

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.

How do I select multiple rows in MySQL?

To select last two rows, use ORDER BY DESC LIMIT 2.


1 Answers

try something like this

SELECT *
FROM `rows`
    cross join `rows`
ORDER BY RANDOM()
LIMIT 200;
like image 57
Roman Pekar Avatar answered Nov 11 '22 13:11

Roman Pekar