MySQL Space Function

The MySQL SPACE is one of the String functions, which returns a string consisting of specified empty space characters. The syntax behind this SPACE is as shown below:

SPACE(Integer)

MySQL SPACE Function Example

The String Space function simply returns whitespace charters for N number of times. The following query shows the use of this function.

From the below MySQL screenshot, the first statement is returning whitespaces.

Well, you may not notice that whitespace. So, let me concat two strings along with the function in the second statement.

SELECT SPACE(5);

SELECT CONCAT('Tutorial', SPACE(5), 'Gateway') AS Website;

SELECT CONCAT('Learn', SPACE(2), 'MySQL');
Example 1

The String Space is also helpful for you to combine (concat) multiple columns. In this example, we will use this function to combine the FirstName and LastName columns. For this, We are going to use the below-shown data

Employee table 2

and the String Function code is:

SELECT EmpID,
       CONCAT(FirstName, SPACE(6), LastName) AS FullName,
       Education,
       YearlyIncome,
       Sales
  FROM `mysql tutorial`.employee;
MySQL Space Function 3

TIP: We used 6 as. the argument value to get Six empty whitespaces between First Name and Last name.