Home > database >  Android Room Kotlin is it possible to draw a random object from the database?
Android Room Kotlin is it possible to draw a random object from the database?

Time:08-31

Is it possible to draw a random object from a database built with Room and put it into the variable?

CodePudding user response:

You can try using random function as SQL.

@Dao
interface SomeDao {
    @Query("select * from some_table order by random() limit 1")
    fun findRandom(): SomeEntity
}
  • Related