OK, curious to see if there is a meaningful solution for this.
I'm having only one table, from which I need to get rows from every user according to the current active site language.
- For every user one row should get selected
- If there is a row with a translation in the active site language it should be prioritized, if there are other rows for that user with different languages
- If there is no row with a translation in the active site language for a user then the oldest translation should get used
I think it's easier to understand looking at some examples I made, instead of me trying to explain it.
I could solve this in PHP filtering stuff out but if there is a query that's not too crazy, I would prefer it.
Of course the query should use the current site language stored in $l.
If someone has a better idea for a title of this question please change :)
id, title, language, created, user
1, a, en, 2019-01-01, 4
2, b, es, 2019-01-02, 4
3, c, de, 2019-01-03, 4
$l = 'de' -- active site language
-> 3 -- getting 'de' translation of user 4 (only user here)
id, title, language, created, user
1, a, en, 2019-01-01, 4
2, b, es, 2019-01-02, 4
$l = 'de' -- active site language
-> 1 -- getting 'en' because no translation for active lang AND en was frist created from user 4
id, title, language, created, user
1, a, en, 2019-01-01, 3
2, b, es, 2019-01-02, 4
3, b, de, 2019-01-03, 4
4, c, de, 2019-01-04, 5
$l = 'de' -- active site language
-> 1,3,4 -- getting de translation of users 4 and 5 AND 'en' translation of user 3 because it's his only
id, title, language, created, user
1, a, en, 2019-01-01, 3
2, b, es, 2019-01-02, 4
3, b, de, 2019-01-03, 4
4, c, de, 2019-01-04, 5
$l = 'es' -- active site language
-> 2,1,4 -- getting es translation of user 4 AND en translation of user 3 AND de translation of user 5
id, title, language, created, user
1, a, en, 2019-01-01, 3
2, b, es, 2019-01-02, 4
3, b, de, 2019-01-03, 4
4, c, de, 2019-01-04, 5
5, d, en, 2019-01-02, 5
$l = 'es' -- active site language
-> 2,1,5 -- getting es translation of user 4 AND en translation of user 3 AND en translation of user 5 (es was created before de from user 5)
See Question&Answers more detail:
os