首先這是有點複雜的解釋。MySQL查詢返回未知值
我遇到了只有一個CONCAT的問題。以下查詢返回表中不存在的'Locale'值。
SELECT client.description, client.name, loc.description
FROM clients AS client
LEFT JOIN FromWhere AS from ON from.id = client.id_from
LEFT JOIN locale AS loc ON loc.id = from.id_loc
client.description LIKE CONCAT('%', ?, '%')
AND IFNULL(client.name, '') LIKE CONCAT('%', ?, '%')
AND IFNULL(loc.description, '') LIKE CONCAT('%', ?, '%')
GROUP BY client.id
ORDER BY client.id DESC
我的表抄錄如下(正確):
-description-------name----------locale
-------------------------------------------
Dude... Testing Paris
No stop Another null
Representing null null
stackover OneMore London
隨着代碼的MySQL之上,如果我改變什麼,我想我得到這個奇怪的結果:
SELECT client.description, client.name, loc.description
FROM clients AS client
LEFT JOIN FromWhere AS from ON from.id = client.id_from
LEFT JOIN locale AS loc ON loc.id = from.id_loc
client.description LIKE CONCAT('%', 'stackover', '%')
AND IFNULL(client.name, '') LIKE CONCAT('%', 'OneMore', '%')
AND IFNULL(loc.description, '') LIKE CONCAT('%', 'OK', '%')
GROUP BY client.id
ORDER BY client.id DESC
-description-------name----------locale
-------------------------------------------
stackover OneMore OK
由於你看,「區域設置」 - >確定不存在.. 這發生在一些值..我無法弄清楚他們之間的連接。
任何想法?
因爲它是一個關鍵字,所以你應該在'from'的別名周圍反引號。你也在'ON loc.id = from.id_loc'和'client.description LIKE CONCAT('%','stackover','%')之間缺少布爾運算符(或可能是WHERE)' – AgRizzo
我確實有第二個運營商..到這裏來,適應,讓你們可以理解我,不知何故,忘了它。 – user3065191