我有一个包含两列的表格,用于存储从英语到德语的翻译(标记为"英语"和"德语")。我用以下查询查找翻译:
window.onload = function() {
document.repaymentcalc.homevalue.onchange = repayment;
document.repaymentcalc.loanamount.onchange = repayment;
document.repaymentcalc.interestrate.onchange = repayment;
document.repaymentcalc.numberpayments.onchange = repayment;
}
我的问题是,有时同一个单词会多次出现在页面上(在这种情况下是单词" A"),我需要在我的SQL结果中匹配数量的行数我要翻译的单词。 SQL将返回如下行:
SELECT german
FROM translate_content
WHERE german = "A" || german = "B" || german = "C" || german = "A";
但我需要它返回
A
B
C
我怎样才能做到这一点?如果它有助于我使用MySQL。
谢谢!
答案 0 :(得分:2)
试试这个:
SELECT german
FROM translate_content
WHERE german = "A"
UNION ALL
SELECT german
FROM translate_content
WHERE german = "B"
UNION ALL
SELECT german
FROM translate_content
WHERE german = "C"
UNION ALL
SELECT german
FROM translate_content
WHERE german = "A"
答案 1 :(得分:1)
我建议使用(0xA0)
:
join
给出问题的结构,你甚至不需要SELECT tc.german
FROM translate_content tc JOIN
(SELECT 'A' as g UNION ALL SELECT 'B' UNION ALL SELECT 'C' UNION ALL SELECT 'A'
) v
ON v.german = tc.german;
表。以下内容将返回您的要求:
translate_content
但是,我怀疑可能涉及不同的列名。 )
答案 2 :(得分:0)
使用DISTINCT,https://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html。
以下是关于DISTINCT和GROUP BY的一个很好的解释:GROUP BY does not remove duplicates