Coding Ref

How to concatenate strings in SQL

How to concatenate strings in SQL

Using ||

To concatenate strings in SQL, you can use the concatenation operator (||) to combine the values of the strings.

Here is an example of how to do this:

SELECT 'Hello' || ' ' || 'World' AS greeting

In this example, the concatenation operator (||) is used to combine the string values 'Hello' and 'World', with a space character (' ') added between the values. The resulting value is aliased as greeting and is returned by the query.

Using the CONCAT function

Alternatively, you can use the CONCAT function to concatenate the strings, like this:

SELECT CONCAT('Hello', ' ', 'World') AS greeting

In this example, the CONCAT function is used to combine the string values 'Hello' and 'World', with a space character added between the values. The resulting value is aliased as greeting and is returned by the query.

You'll also like

Related tutorials curated for you

    Pandas read SQL

    Block comments in SQL

    How to get the day of the week in SQL

    What is the AS statement in SQL?

    How to concatenate strings in SQL

    What is SQL ALL?

    How to combine two columns in SQL

    How to use between inclusive in SQL?

    Filtering in GraphQL

    Find column names in SQL

    What is a blind SQL injection?

    What is CAST function in SQL?