This is probably a bad example, but I think it’s quite simple.
Let’s say a web search engine (e.g. Google) is retrieving results (links to websites) of a search performed by the user and it’s supposed to order them according to a given priority of languages and countries at the same time. Say,
Language priorities
1. English
2. Spanish
3. Italian
...
Country priorities
1. USA
2. England
3. Canada
4. Spain
5. Mexico
...
So, the result would be something ordered like
Websites in english and from the USA
Websites in spanish and from the USA or in english and from England
...
Websites in italian and from Mexico (?).
A query like
SELECT url FROM websites
WHERE (
language = english
OR language = spanish
OR language = italian
) AND (
country = USA
OR country = England
OR country = Canada
OR country = Spain
OR country = Mexico)
obviously wouldn’t work because it provides a condition, not a priority. Using ORDER BY language or ORDER BY timezone wouldn’t work either because it orders it alphabetically. So, how is the best way to go about this in SQL?
Assuming that the languages and countries are in their own tables and that the websites table references those two, you
order bythe two fields that hold the priority of each table..something like