Skip to content

Is there a way to get a random record and/or order a query randomly with SQLmodel? #1490

Discussion options

You must be logged in to vote

Try this:

from sqlalchemy import func

task = session.exec(select(Tasks).order_by(func.random())).first()

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
3 participants
Converted from issue

This discussion was converted from issue #277 on August 12, 2025 08:29.