Skip to main content
Question

InlineQuerier SQL random statement ("Random()", "Rand()", or "RND()"?) in conjunction with "LIMIT"

  • November 30, 2017
  • 4 replies
  • 24 views

bwasserstein
Participant
Forum|alt.badge.img

Hello All,

Question regarding the InlineQuerier transformer that harnesses SQL. I'm trying to select a random subset of records from a table. Here's the SQL code in MS-Access that works (different syntax).

SELECT TOP 200 *
FROM (SELECT Rnd(ID) AS RandomID, * FROM TableNameHere)  AS TableNameRandomSelection
ORDER BY RandomID;

I think the InlineQuerier uses SQLite...correct me if I'm wrong. I'm uncertain as to which random function I should use and where to implement it within the code string.

RND()? RANDOM()? RAND()?

And can I add an argument to this function? I need to generate a random sample of records based off the table's primary key ("ID" in this case).

This code works, but it only returns the first 200 records in the table (not the random sample I'm looking for), but I feel like I'm close and just need to work a random function in there...

SELECT *
FROM TableName
LIMIT 200
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3434 replies
  • November 30, 2017
SELECT "ID" FROM "Table" WHERE "ID" IN (SELECT "ID" FROM "Table" ORDER BY RANDOM() LIMIT 200)

Something like the above should work


bwasserstein
Participant
Forum|alt.badge.img
  • Author
  • Participant
  • 20 replies
  • November 30, 2017

A reply to my own post....Just FYI.

This works...

SELECT * FROM TableNameHere
WHERE ID IN (SELECT ID FROM TableNameHere ORDER BY RANDOM() LIMIT 200)


bwasserstein
Participant
Forum|alt.badge.img
  • Author
  • Participant
  • 20 replies
  • November 30, 2017
SELECT "ID" FROM "Table" WHERE "ID" IN (SELECT "ID" FROM "Table" ORDER BY RANDOM() LIMIT 200)

Something like the above should work

Thanks egomm. Beat me to it :)

 

 


takashi
Celebrity
  • 7843 replies
  • November 30, 2017

A reply to my own post....Just FYI.

This works...

SELECT * FROM TableNameHere
WHERE ID IN (SELECT ID FROM TableNameHere ORDER BY RANDOM() LIMIT 200)

 

This query could work as well.

 

select * from tablename order by random() limit 200