Introduction
CONCAT and CONCAT_WS help join text pieces together to make one longer text. This is useful when you want to combine names, addresses, or other text parts.
CONCAT(string1, string2, ...) CONCAT_WS(separator, string1, string2, ...)
SELECT CONCAT('Hello', ' ', 'World');
SELECT CONCAT_WS('-', '2024', '06', '15');
SELECT CONCAT(first_name, last_name) FROM users;
SELECT CONCAT_WS(' ', first_name, last_name) FROM users;
CREATE TABLE people (first_name VARCHAR(20), last_name VARCHAR(20)); INSERT INTO people VALUES ('John', 'Doe'), ('Jane', 'Smith'); SELECT CONCAT(first_name, last_name) AS full_name_no_space, CONCAT_WS(' ', first_name, last_name) AS full_name_with_space FROM people;
CONCAT and CONCAT_WS in SQL?CONCAT behaviorCONCAT joins text parts directly without any separator.CONCAT_WS behaviorCONCAT_WS joins text parts but inserts a separator you specify between them.CONCAT joins strings directly; CONCAT_WS adds a separator between strings. -> Option Afirst_name and last_name with a space using CONCAT_WS?CONCAT_WS syntaxusers with columns city = 'Paris', country = 'France', what is the result of this query?SELECT CONCAT(city, ', ', country) AS location FROM users;
SELECT CONCAT_WS(first_name, ' ', last_name) FROM employees;
street, city, and zipcode separated by commas. Which query correctly uses CONCAT_WS to achieve this, and what will be the output if street = '123 Main St', city = NULL, zipcode = '90210'?Pass the test and this pattern moves unknown