
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to align a column right-adjusted in MySQL?
You can use LPAD() from MySQL for this. Let us first create a table −
mysql> create table DemoTable ( FullName varchar(100) ); Query OK, 0 rows affected (0.81 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Sam Williams'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Carol Taylor'); Query OK, 1 row affected (0.47 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+ | FullName | +--------------+ | John Smith | | David Miller | | Sam Williams | | Carol Taylor | +--------------+ 4 rows in set (0.00 sec)
Following is the query to align a column right-adjusted −
mysql> select lpad(FullName,70,' ') from DemoTable;
This will produce the following output −
+------------------------------------------------------------------------+ | lpad(FullName,70,' ') | +------------------------------------------------------------------------+ | John Smith | | David Miller | | Sam Williams | | Carol Taylor | +------------------------------------------------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to Align Column DIVs as Left-Center-Right with CSS Flex
- How to Right-align flex item?
- How to right align the text in a ComboBox in Java
- How to right-align a menu in the menu bar with Java?
- How to Align a Column of Numbers by Decimal Point in Excel?
- How to align text to the right in ttk Treeview widget?
- Right align a Bootstrap dropdown menu
- How to align axis label to the right or top in Matplotlib?
- How to split a column in MySQL?
- How to align 3 files based on first column value
- Align Dropdown to the right with Bootstrap
- Write a program in Python to caluculate the adjusted and non-adjusted EWM in a given dataframe
- How to add a column in a table in MySQL?
- How to create a Cumulative Sum Column in MySQL?
- How to substring value in a MySQL table column?

Advertisements