MySQL | Strings

Concatenate Strings

You can concatenate strings or column values by using the concat function.

Function Format

concat(string_or_column_name, string_or_column_name, ...)

Example

SELECT concat("abc","123") 

When you run the example above, the following result is displayed.

abc123

Cut a String from the Left

The left function cuts a string starting from the left.

Function Format

left(column_name_or_string, length_to_cut_from_the_left)

Example

SELECT left("abcdef", 3)

When you run the example above, the following result is displayed.

abc

Cut a String from the Right

The right function cuts a string starting from the right.

Function Format

right(column_name_or_string, length)

Example

SELECT right("abcdef", 3)

When you run the example above, the following result is displayed.

def

Cut a String from the Middle

The substring function cuts a string from the middle.

Function Format

substring(column_or_string, start_position, length);

Example

SELECT substring("abcdef", 3, 2) 

When you run the example above, the following result is displayed.

cd