i have a simple table master and the master_lang that holds the language data
I am trying to write an sql command that will return the data based on current language.
Here is an example :
record 1 has in master_lang languages EN,FR
record 2 has in master_lang languages EN
record 3 has in master_lang languages FR
record 4 has in master_lang languages EN,FR
So if current language is EN i want to return
record 1
record 2
record 4
(order by the name on EN language)
record 3
(order by the name on FR language)
If i can make it more simple i would say " give me first all records from current language order by name and then for all other languages order by name "
Here is my SQL so far
SELECT
DISTINCT(master.masterID),
langData.*,
master.*
FROM master_table as master
INNER JOIN lang_table as langData ON
langData.masterID=master.masterID
GROUP BY master.masterID
ORDER BY
CASE
WHEN langData.lang='currentLang' THEN 1 ELSE 999 END ,
master.name desc LIMIT 0,10
BUT GROUP BY master.masterID does not follow ORDER BY
I think that first Group and then ORDER
I dont want to
INNER JOIN lang_table as langData ON
langData.masterID=master.masterID
AND langData.lang='currentLnag'
you shouldn’t store multiple values in a single column. you should normalize your data so that the languages are broken out into a separate table, one new row per language spoken/written.
SELECT please
, list
, the
, columns
, you
, want
FROM master_table AS master
INNER
JOIN lang_table AS langData
ON langData.masterID = master.masterID
ORDER
BY CASE WHEN langData.lang = 'currentLang'
THEN 1 ELSE 999 END
, master.name DESC LIMIT 0,10