The scenario is that I have a table that looks like this, with book IDs, their titles in English and/or French, and their sales. There are also some nulls. Some books will have only English or only French titles. Some may have multiple of both or either.
ID | Title | Language | Sales |
---|---|---|---|
12345 | Sorceror's Stone | English | 50,000,000 |
12345 | Philosopher's Stone | English | 50,000,000 |
12345 | A L'ecole de sorcier | French | 50,000,000 |
33333 | NULL | NULL | NULL |
67890 | A Christmas Carol | English | 65,000,000 |
67890 | Un Chant de Noel | French | 65,000,000 |
24680 | La Fascination | French | 30,000,000 |
24680 | La Crépuscule | French | 30,000,000 |
13579 | NULL | NULL | NULL |
Basically, I want to narrow down this table as follows:
- If at least 1 English title exists, we want the alphabetically first English title.
- Else if at least 1 French title exists, we want the alphabetically first French title.
- Else, just have string null.
I want my resultant table to look like:
ID | Title | Language | Sales |
---|---|---|---|
12345 | Philosopher's Stone | English | 50,000,000 |
33333 | null | null | null |
67890 | A Christmas Carol | English | 65,000,000 |
24680 | La Crépuscule | French | 30,000,000 |
13579 | null | null | null |