When I perform the following query
select * from table where c2 = 11 or c3 = 15 or c7 = false
I’m getting this result
| c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 |
| 24 | 11 | 15 | NNN | NNN | | true | false |
| 28 | 11 | 13 | NNN | NNN | | true | false |
| 26 | 11 | 15 | NNN | NNN | wwwww | false | false |
| 25 | 11 | 2 | NNN | NNN | qqqq | false | false |
| 33 | 23 | 31 | NNN | NNN | | false | false |
| 31 | 23 | 15 | NNN | NNN | | false | false |
| 31 | 23 | 15 | NNN | NNN | | true | false |
| 25 | 11 | 23 | NNN | NNN | qqqqw2 | false | false |
| 29 | 11 | 22 | NNN | NNN | | true | false |
I’m trying to order this by search coincidences, like this:
| c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 |
| 26 |[11]|[15]| NNN | NNN | wwwww |[false]| false |
| 24 |[11]|[15]| NNN | NNN | | true | false |
| 25 |[11]| 2 | NNN | NNN | qqqq |[false]| false |
| 31 | 23 |[15]| NNN | NNN | |[false]| false |
| 25 |[11]| 23 | NNN | NNN | qqqqw2 |[false]| false |
| 28 |[11]| 13 | NNN | NNN | | true | false |
| 29 |[11]| 22 | NNN | NNN | | true | false |
| 31 | 23 |[15]| NNN | NNN | | true | false |
| 33 | 23 | 31 | NNN | NNN | |[false]| false |
So the row that has the 3 options will be on top
then the all the rows that matches at least 2 optiones (in no specific order)
and last all the rows that matches 1 option,
Is there a way to achieve this order? because the other option I have is doing combination of options with and statement and then use union with all the results, but it seems to be a lot more
Thanks in advance
You need to add an order by clause:
(SQL Fiddle example)