Skip to content
Advertisement

How to select matching results with other random results in mysql

I want to select all the matching results in a database table with also random results but with the matching results being at the top. With the way, I am doing now I am using two queries first one being the matching query, and if the count is zero I now select random results. I would like to do this with just one query.

Advertisement

Answer

You could attempt using a UNION ALL query as follows.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement