Erin Evergreen
Erin Evergreen

Reputation: 1

What is the difference between CONCAT vs CONCAT_WS in SQL

Please clarify what information is pulled and how it is reorganized using CONCAT vs CONCAT_WS in SQL. See example below for more details.

For example,

CONCAT('Google', '.com') creates Google.com

but I don't understand how

CONCAT_WS ('.', 'www', 'google', 'com') also create Google .com

To me it seems like it would create .wwwgooglecom

Why is this not the case?

For example,

CONCAT('Google', '.com') creates Google.com

but I don't understand how

CONCAT_WS ('.', 'www', 'google', 'com') also create Google .com

To me it seems like it would create .wwwgooglecom

Why is this not the case?

Upvotes: -2

Views: 809

Answers (2)

ne.romantic
ne.romantic

Reputation: 11

CONCAT_WS will handle NULL values as empty strings, whereas CONCAT will return NULL.

Upvotes: 1

Nikhil Patel
Nikhil Patel

Reputation: 11

CONCAT just combines the values provided as arguments as it is. For example - CONCAT('www','.google','.com') produces www.google.com

CONCAT_WS will combine the provided values based on the separator, which is the first argument. For example - CONCAT_WS('.', 'www','google','com') will produce www.google.com.

Upvotes: 0

Related Questions