How can I select a random record using SQL?

I need assistance with selecting a random record from an SQL table using only standard SQL. I’m interested in a method that can closely emulate true randomness without relying on any external functions or non-standard SQL constructs. I have explored a few approaches but haven’t found one that consistently works across different SQL systems. Could someone provide a strategy or query that reliably extracts a random row from a table, ensuring that the results appear as unpredictable as possible when executed?

Standard SQL does not provide direct support for generating random results uniformly, which makes selecting a true random record challenging. One strategy that has worked in practice involves using a subquery that calculates a pseudo-random value based on available columns, such as the primary key, and then ordering on that value before limiting the result set. Although this does not guarantee cryptographic randomness, it produces sufficient unpredictability for many applications. Care should be taken when implementing such queries to ensure compatibility across different SQL systems, and extensive testing is recommended.

hey, i’ve been pondering that too; maybe using a hashed primary key might work? curious if any one’s tried this on larger dbs or got better ideas, anyone? lets discuss!