Tags
MySQL
Asked 7 years ago
24 Sep 2016
Views 1446
debugger

debugger posted

CONCAT VS CONCAT_WS

Want to know differance and pros and cons of CONCAT VS CONCAT_WS , i am dealing with Mysql
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

CONCAT stand for concat two string or field in the MySql.


select concat('David','Jason')


Result will be

DavidJason


CONCAT_WS do same , concating two string or field but you can pass on "Separator" to join with. its like "implode"
Syntax :: CONCAT_WS ("Separator",'String/Field',,,)
Example

select concat(",",'David','Jason')

it will join two string with seprator ","
so result will be

David,Jason


ravi

ravi
answered Nov 30 '-1 00:00

MySQL CONCAT function , concat two or more string into single String.
when MySQL CONCAT_WS function , concat two or more string with separator.

CONCAT

SELECT concat( ",", 'i', 'am', 'coder' ) 


result ::
,iamcoder

CONCAT_WS

SELECT concat_ws( ",", 'i', 'am', 'coder' ) 


result ::
i,am,coder

Post Answer