WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

MySQL · Intermediate · question 36 of 100

How do you use the CONCAT, CONCAT_WS, and SUBSTRING functions in MySQL?

📕 Buy this interview preparation book: 100 MySQL questions & answers — PDF + EPUB for $5

In MySQL, the CONCAT, CONCAT_WS, and SUBSTRING functions are used for string manipulation. Here’s an explanation of each function with some examples:

1. **CONCAT function:** The ‘CONCAT‘ function is used to concatenate two or more strings into a single string. It takes one or more string arguments and returns a string.

Syntax:

CONCAT(string1, string2, ...)

Example:

SELECT CONCAT('Hello', ' ', 'World');

Output:

'Hello World'

2. **CONCAT_WS function:** The ‘CONCAT_WS‘ function is used to concatenate strings with a separator. It takes a separator and two or more string arguments and returns a string with the separator between each of the strings.

Syntax:

CONCAT_WS(separator, string1, string2, ...)

Example:

SELECT CONCAT_WS(',', 'John', 'Doe', '25', 'Male');

Output:

'John,Doe,25,Male'

3. **SUBSTRING function:** The ‘SUBSTRING‘ function is used to extract a substring from a string. It takes a string argument and two integer arguments that represent the starting position and the length of the substring.

Syntax:

SUBSTRING(string, start, length)

Example:

SELECT SUBSTRING('Hello World', 7, 5);

Output:

'World'

These functions are useful for manipulating strings in MySQL, whether you need to join strings together, add separators between strings, or extract a substring from a larger string.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic MySQL interview — then scores it.
📞 Practice MySQL — free 15 min
📕 Buy this interview preparation book: 100 MySQL questions & answers — PDF + EPUB for $5

All 100 MySQL questions · All topics