Nik's Technology Blog

Travels through programming, networks, and computers

MySQL vs TSQL Concatenation CONCAT()

Following on from an entry posted last year concerning converting SQL queries from Microsoft TSQL to MySQL I've come across another function which is treated somewhat differently in MySQL than TSQL.

The following SQL code adds the .jpeg file extension onto the end of the image names from tblImages.

TSQL Concatenation

SELECT ImageName+'.jpeg' FROM tblImages

The above SQL syntax is used on Microsoft SQL Server, Microsoft Access and Sybase

MySQL Concatenation

SELECT CONCAT(ImageName,'.jpeg') FROM tblImages

Oracle Concatenation

SELECT ImageName || '.jpeg' FROM tblImages

The Oracle syntax is the syntax recommended by the SQL specification. It uses 2 pipes || instead of a plus + sign. This avoids the problems of trying to concatenate integer fields which might otherwise result in an unwanted addition.

Previous entry: T-SQL TO MYSQL CONVERSIONS

Comments are closed