Wednesday, July 7, 2010

MySql - Aggregate function for choosing first choice, second choice, third choice, etc?

Programmer Question

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?



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails