Last active
November 19, 2023 09:16
-
-
Save HamidMolareza/be281d2be2d3d447d604c6a32597711c to your computer and use it in GitHub Desktop.
CONCAT vs CONCAT_WS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://quera.org/college/8939/chapter/32512/lesson/108911/ | |
-- Create a sample table | |
CREATE TABLE sample_table | |
( | |
id INT PRIMARY KEY AUTO_INCREMENT, | |
first_name VARCHAR(50), | |
last_name VARCHAR(50) | |
); | |
-- Insert sample data | |
INSERT INTO sample_table (first_name, last_name) | |
VALUES ('John', 'Doe'), | |
('Jack', NULL), | |
('Bob', 'Johnson'); | |
select * | |
from sample_table; | |
-- Test CONCAT | |
SELECT id, | |
CONCAT(first_name, ' ', last_name) AS full_name_concat | |
FROM sample_table; | |
-- Test CONCAT_WS | |
SELECT id, | |
CONCAT_WS(' ', first_name, last_name) AS full_name_concat_ws | |
FROM sample_table; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CONCAT
output:CONCAT_WS
output: