Imagine I have the following data in a table called “messages”:
message_id | language_id | message
------------------------------------
1 en Hello
1 de Hallo
1 es Hola
2 en Goodbye
2 es Adios
(Note that I don’t have a German translation for “Goodbye.”)
I want to select the messages for a user who speaks English and German, but prefers German.
Meaning, I want a result set that looks like:
message_id | language_id | message
------------------------------------
1 de Hallo
2 en Goodbye
But, um, it’s proving tricky. Any ideas?
The fastest solution I’ve found which gives the resultset I’m after is described in this article:
http://onlamp.com/pub/a/mysql/2007/03/29/emulating-analytic-aka-ranking-functions-with-mysql.html