© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
5 replies
MaGnezij

Order by random()

Hi, is it possible to get random order of the query rows, while doing 2 unions.
Code:
SELECT 
o.id,
o.name, 
o.city,
o.image,
true as isOffer,
false as isEvent,
false as isPlace
FROM offers o
UNION
SELECT
e.id,
e.name as event_name, 
e.city,
e.image,
false as isOffer,
true as isEvent,
false as isPlace
FROM events e
UNION
SELECT 
p.id,
p.name,
p.city,
p.images as image,
false as isOffer,
false as isEvent,
true as isPlace
FROM places p
SELECT 
o.id,
o.name, 
o.city,
o.image,
true as isOffer,
false as isEvent,
false as isPlace
FROM offers o
UNION
SELECT
e.id,
e.name as event_name, 
e.city,
e.image,
false as isOffer,
true as isEvent,
false as isPlace
FROM events e
UNION
SELECT 
p.id,
p.name,
p.city,
p.images as image,
false as isOffer,
false as isEvent,
true as isPlace
FROM places p
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Order by in js sdk
SupabaseSSupabase / help-and-questions
4y ago
Order by multiple columns in supabase
SupabaseSSupabase / help-and-questions
13mo ago
Order by view count in JS library
SupabaseSSupabase / help-and-questions
4y ago
order by does not work in a function
SupabaseSSupabase / help-and-questions
4y ago