In MySQL I can use the RAND() function, is there any alternative in SQLite 3?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- sqlyog export query result as csv
For a much better performance use this in SQLite:
This is also applicable to MySQL. This runs faster because SQL engines first load projected fields of rows to memory then sort them, here we just load and random sort the id field of rows, then we get X of them, and find the whole rows of these X ids which is by default indexed.
using random():
EDIT (by QOP): Since the docs on SQLite Autoincremented columns states that:
The above is only true if you don't have a
INTEGER PRIMARY KEY AUTOINCREMENT
column (it will still work fine withINTEGER PRIMARY KEY
columns). Anyway, this should be more portable / reliable:ROWID
,_ROWID_
andOID
are all aliases for the SQLite internal row id.Solved: