What is the best way to display in Terminal a MySQL SELECT returning too many fields?


To achieve this, you can use the following syntax in MySQL −

select *from yourTableName\G;

Here, G can be used for vertical purpose. You need to add yourTableName.

Let us create a table in order to understand the above syntax. Creating a table with the help of CREATE command.

The following is the query to create a table −

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

Now you can insert records in the table with the help of INSERT command. The query is as follows −

mysql> insert into TooManyFieldsreturnDemo values(1,'John',21);
Query OK, 1 row affected (0.19 sec)
mysql> insert into TooManyFieldsreturnDemo values(2,'Johnson',22);
Query OK, 1 row affected (0.15 sec)
mysql> insert into TooManyFieldsreturnDemo values(3,'Sam',23);
Query OK, 1 row affected (0.10 sec)
mysql> insert into TooManyFieldsreturnDemo values(4,'Carol',24);
Query OK, 1 row affected (0.14 sec)
mysql> insert into TooManyFieldsreturnDemo values(5,'David',25);
Query OK, 1 row affected (0.12 sec)

Now, let us apply the above syntax to achieve the desired result discussed before. The query is as follows −

mysql> select *from TooManyFieldsreturnDemo\G;

Here is the output −

*************************** 1. row ***************************
Id: 1
Name: John
Age: 21
*************************** 2. row ***************************
Id: 2
Name: Johnson
Age: 22
*************************** 3. row ***************************
Id: 3
Name: Sam
Age: 23
*************************** 4. row ***************************
Id: 4
Name: Carol
Age: 24
*************************** 5. row ***************************
Id: 5
Name: David
Age: 25
5 rows in set (0.00 sec)

Updated on: 30-Jul-2019

95 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements