SPACE(): to add space in Query

SPACE Query takes integer N as argument.
We can add one start and end string to display the space between them
SELECT  '#', SPACE( 15 ) ,  '#' 
Output is here
#	             	#
We can use SPACE with our student table
SELECT  name , SPACE(10), class , mark, sex  FROM `student`
John Deo Four75female
Max Ruin Three85male
Arnold Three100male
Krish Star Four60female
John Mike Four60female
Alex John Four55male


We can add blank space to data in a Column by using update query
UPDATE student set name=CONCAT(space(5),name)
We added space before all names in our student table.

CONCAT to add string

Removing Space

To remove space from Left we can use LTRIM, to remove space from Right we can use RTRIM and to remove from both sides we can use TRIM

Read more on UPDATE Query

PHP Script

MySQLi database connection string

require "config.php";// Database connection
$query="SELECT  name , SPACE(10), class FROM `student`";
if ($result_set = $connection->query($query)) {
while($row = $result_set->fetch_array(MYSQLI_ASSOC)){
echo $row['name'],$row['SPACE(10)'],$row['class']."<br>";

SQL String References elt(): String from the postion

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    SQL Video Tutorials

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer