How can I request a random column (or as close to truly random as is possible) in pure SQL?
I want to select any one column randomly from a table.
I have searched lot regarding this on google.
How can I request a random column (or as close to truly random as is possible) in pure SQL?
I want to select any one column randomly from a table.
I have searched lot regarding this on google.
You can select a random record, but all columns must be referenced by name and not even position.
The only way you can force this is:
Simply there is no way to do it with pie SQL.
In Microsoft SQL, you can achieve this by ordering columns by randomized number (
NEWID
):This may help you, It is done with SQL Server. Here you are randomly selecting a column of table [DimProduct]
Result1:
Result2:
Dependent on your DBMS the catalogue looks a bit different. For mysql you could get a random column like:
and then incorporate that into your query. Other vendors may have a slightly different look of the catalogue, but the idea will be the same.
Why do you want to retrieve a random column?