MySQL Space Function

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

SPACE(Integer)

MySQL SPACE Example

The MySQL 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');
MySQL Space Function 1

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

MySQL Space Function 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.