sql concatenate columns code example

Example 1: sql concat string with column value

SELECT CONCAT(name, "string_value") AS name
FROM 
  users;

Example 2: mysql concat and use as where column

select * from table where concat_ws(' ',first_name,last_name) 
like '%$search_term%';

Example 3: Concatenate columns in table

/*  Takes several columns to form a single name  */
select concat(prefix,' ',first,' ',last,' ',suffix) as title from names

Example 4: concat two columns in sql server

select Convert(nvarchar(50),ID)+'-'+Convert(nvarchar(50),Year) as ID_Year from tablename

Tags:

Sql Example