Table of contents
Introduction
In SQL, you can concatenate two strings from two columns using the
CONCAT
function or the+
operator, depending on the database system you are using.Using CONCAT Function:
SELECT CONCAT(column1, ' ', column2) AS concatenated_string
FROM your_table;
Replace
column1
andcolumn2
with the actual column names you want to concatenate, and replaceyour_table
with the name of your table. The space within the single quotes is added for a space between the two concatenated strings. You can adjust it based on your desired separator.Using + Operator (for some database systems):
SELECT column1 + ' ' + column2 AS concatenated_string
FROM your_table;
Again, replace
column1
,column2
, andyour_table
with the appropriate column names and table name. Note that the usage of the+
operator for string concatenation may vary between different database systems. TheCONCAT
function is more widely supported across different SQL databases.Here's an example for the first case, assuming you have a table called
employees
with columnsfirst_name
andlast_name
:
SELECT CONCAT(first_name, ' ', last_name) AS full_name
FROM employees;
- This would result in a new column called
full_name
containing the concatenated strings offirst_name
andlast_name
with a space in between. Adjust the column and table names based on your specific database schema.