Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql - concat in query with left outer join

I don't get it. I've tried:

SELECT
table1.name, CONCAT( country,  '.', id ) AS table1.code,
table2.name
FROM tabel1
LEFT OUTER JOIN
table2 ON ( table1.code = table2.code )

I need to combine country and id to country.id because table2.code has this schema.

Thanks in advance.

like image 573
Bob Avatar asked Mar 09 '13 17:03

Bob


1 Answers

If I understand you correct you might need something like this

SELECT t1.name t1_name,
       t2.name t2_name
FROM table1 t1 LEFT JOIN
     table2 t2 ON CONCAT(t1.country,  '.', t1.id ) = t2.code

SQLFiddle example

like image 177
peterm Avatar answered Sep 24 '22 03:09

peterm