我想在我的网站上应用多语言支持。我创建了一个这样的表:

id | textID | langID |   text   | status
1  | 1453   | 36     | sign up  |  1
2  | 1453   | 147    | kayıt ol |  1
3  | 1454   | 36     | login    |  1


我创建了一个这样的sql:

SQL;

SELECT `textID`
     , `text`
  FROM `text`
 WHERE `langID` = ( CASE WHEN `langID` = '147' and `status` THEN '147' ELSE '36' END )
   and `textID` in ('1453','1454')


结果;

textID  | text
1453    | sign up
1453    | kayıt ol
1454    | login


1453,1454在“ where in”内部,但是我的代码显示1453的两种语言,如何为一种语言或默认语言执行sql?

最佳答案

SELECT `textID`, `text`
FROM `text`
WHERE `textID` IN (1453, 1454) AND `langID` = 147

UNION

SELECT `textID`, `text`
FROM `text`
WHERE `textID` NOT IN (
    SELECT `textID`
    FROM `text`
    WHERE `textID` IN (1453, 1454) AND `langID` = 147
) AND `langID` = 36

关于mysql - 在“where in”语句中使用“case”-,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32504760/

10-11 04:47