CONCAT in SQL

For Complete YouTube Video: Click Here

In this class, we will understand CONCAT in SQL.

We have already discussed the concept of many logical operators.

Getting Text and Changing it

From this class, we will understand “Getting Text and Changing it” operators.

SQL provides a variety of features to perform operations on the text obtained as the query’s output.

We can display the output of the query in different ways.

CONCAT in SQL

In this class, we will understand one of the methods, CONCAT.

CONCAT or ||: Concatenates two strings together.

To understand this, we will consider the table as shown below.

CONCAT in SQL 1
CONCAT in SQL 1

Let us try to CONCATENATE the column’s name and id in the query’s output as shown below.

SELECT name||id FROM students;

In the above query, we are concatenating the values in the name and id columns.

The output of the query is as shown below.

CONCAT in SQL 2
CONCAT in SQL 2

In the above output, the values are combined and look very clumsy.

We can use separators with the CONCAT.

CONCAT with separators

The query with separators is as shown below.

SELECT name||’-‘||id FROM students;

The output of the query is as shown below.

CONCAT in SQL 3
CONCAT 3

Now the output looks clear.