I need an alternative function CONCAT
in SQL. The reason is that they are asking me in a school project to be able to use, for example, an alternative to the already mentioned function in the following search:
SELECT CONCAT(A.NOMBRE, A.A_PATERNO, A.A_MATERNO) NOMBRE, M.NOMBRE
FROM ALUMNOS A, MATERIAS M, CALIFICACIONES C
WHERE A.NUM_CONTROL=C.NUM_CONTROL AND M.CVE_MATERIA=C.CVE_MATERIA;
In MySQL you can concatenate in several ways:
Using
CONCAT()
, which returns the string resulting from the union/concatenation of the parameters. This is the most common method, but it is the one you want to avoid. Example:Using
CONCAT_WS()
, which returns the string resulting from the union of the parameters using the first as a connector between the others (it is a variation ofCONCAT()
but with a separator, hence theWS
: With Separator ). Example:Using pipes (
||
) , you can tell MySQL to use pipes to concatenate using modePIPES_AS_CONCAT
( , or , , , orANSI
modes would also do, although the latter 5 are deprecated and should not be used ). Example:DB2
MAXDB
MSSQL
ORACLE
POSTGRESQL
All three options above will return the same result. I have created an example in DB Fiddle where you can see all three methods working.
You can use + to concatenate: