How to display records vertically in MySQL command line?


You can use backward slash followed by G i.e. \G instead of semicolon(;). The syntax is as follows to show records vertically in MySQL command line.

SELECT *FROM yourTableName\G

To understand the above syntax, let us create a table. The query to create a table is as follows

mysql> create table showRecordsVertically
   -> (
   -> Id int,
   -> Name varchar(100),
   -> Age int
   -> );
Query OK, 0 rows affected (2.10 sec)

Insert some records in the table using insert command. The query is as follows

mysql> insert into showRecordsVertically values(101,'John',23);
Query OK, 1 row affected (0.15 sec)

mysql> insert into showRecordsVertically values(104,'Carol',20);
Query OK, 1 row affected (0.17 sec)

mysql> insert into showRecordsVertically values(107,'Bob',22);
Query OK, 1 row affected (0.11 sec)

mysql> insert into showRecordsVertically values(110,'David',29);
Query OK, 1 row affected (0.21 sec)

mysql> insert into showRecordsVertically values(113,'Mike',28);
Query OK, 1 row affected (0.14 sec)

Now you can show records vertically using \G. The query is as follows

mysql> select *from showRecordsVertically\G

The following is the output

*************************** 1. row ***************************
Id: 101
Name: John
Age: 23
*************************** 2. row ***************************
Id: 104
Name: Carol
Age: 20
*************************** 3. row ***************************
Id: 107
Name: Bob
Age: 22
*************************** 4. row ***************************
Id: 110
Name: David
Age: 29
*************************** 5. row ***************************
Id: 113
Name: Mike
Age: 28
5 rows in set (0.00 sec)

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements