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 1

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

-- STRING SPACE in MySQL example
SELECT SPACE(5);

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

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

From the above MySQL screenshot, the first statement is returning empty spaces.

SELECT SPACE(5);

Well, you may not notice that empty space. So, let me concat two strings along with the space function.

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

MySQL SPACE Function Example 2

The String Space in MySQL also helpful for you combine (concat) multiple columns. In this example, we are going to use the space 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(5), LastName) AS FullName,
       Education,
       YearlyIncome,
       Sales
  FROM `mysql tutorial`.employee;
MySQL Space Function 3

TIP: We used this SPACE(6) to get Six empty spaces between First Name and Last name.