我不明白。我已经试过:MySql - 带左外连接的查询中的concat
SELECT
table1.name, CONCAT(country, '.', id) AS table1.code,
table2.name
FROM tabel1
LEFT OUTER JOIN
table2 ON (table1.code = table2.code)
我需要country
和id
结合country.id
因为table2.code
有这个架构。
在此先感谢。
我不明白。我已经试过:MySql - 带左外连接的查询中的concat
SELECT
table1.name, CONCAT(country, '.', id) AS table1.code,
table2.name
FROM tabel1
LEFT OUTER JOIN
table2 ON (table1.code = table2.code)
我需要country
和id
结合country.id
因为table2.code
有这个架构。
在此先感谢。
如果我理解你纠正你可能需要像这样
SELECT t1.name t1_name,
t2.name t2_name
FROM table1 t1 LEFT JOIN
table2 t2 ON CONCAT(t1.country, '.', t1.id) = t2.code
对于任何人拉他的头发,因为的ON CONCAT()
表现不佳加入:确保你投你的非字符串值为CHAR
它提高了天文数据的性能:
SELECT t1.name t1_name,
t2.name t2_name
FROM table1 t1 LEFT JOIN
table2 t2 ON CONCAT(t1.country, '.', CAST(t1.id AS CHAR)) = t2.code
说明在MySQL的文档隐藏了CONCAT()功能:
...如果所有参数均为非二进制字符串,其结果是一个非二进制字符串 。如果参数包含任何二进制字符串,则结果是一个 二进制字符串。一个数字参数被转换为其等效的 二进制字符串形式;如果你想避免这种情况,你可以为这个去Aurimas Mikalauskas使用显式 型投 ...
信用。
什么问题?你得到空吗? – 2013-03-09 17:28:17
您是否注意到您键入了'FROM tabel1'而不是'table2'? – 2013-03-09 17:29:10