I have a destination id and I want to select other destinations, ordered first by the given destination’s country followed by others. (preferably without using subquery)
destination:
- id
- name
destination_visa
- id_destination
- id_visa
visa
- id_visa
- country
How do I select the given destination’s country and then order other destination based on this destination’s country, preferably without using a subquery ?
SQLFiddle: http://sqlfiddle.com/#!2/31503/3
Is this what you had in mind?
There is still a subquery, which might be preselected into a variable.
I don’t think a subquery should present a problem because it is not correlated to outer query, meaning it should be executed only once. As for order by, nulls are sorted first so I used that to nullify country matching given destination. Alternatively you might use this to make intend more clear: