Home > Database > Mysql Tutorial > How to Suppress Header Output for a Specific SQL Statement in MySQL?

How to Suppress Header Output for a Specific SQL Statement in MySQL?

Barbara Streisand
Release: 2024-11-18 21:28:02
Original
992 people have browsed it

How to Suppress Header Output for a Specific SQL Statement in MySQL?

Suppressing Header Output for a Specific SQL Statement

When executing multiple SQL statements in batch mode using the mysql command-line tool, scenarios may arise where you desire to suppress the display of column headers for a particular SELECT statement. This article explores how to achieve this behavior effectively.

To suppress column headers for a single SELECT statement, invoke mysql with the -N option (or its alias, -skip-column-names):

mysql -N ...
Copy after login

For instance, consider the following batch of SQL statements:

use testdb;
select * from names;  # Display column headers
select * from names;  # Suppress column headers
Copy after login

Executing this batch with the -N option applied to the second SELECT statement would produce the following output:

+------+-------+
| id  | name  |
+------+-------+
| 1   | pete  |
| 2   | john  |
| 3   | mike  |
+------+-------+
3 rows in set (0.00 sec)

pete
john
mike
Copy after login

As evident, column headers are displayed for the first SELECT statement but not for the second.

To further enhance the output presentation, you can employ the -s (or --silent) option to remove the grid surrounding the results, separating columns with TAB characters:

mysql -sN ...
Copy after login
Copy after login

Alternatively, you can utilize both -s and -N simultaneously to remove both headers and the grid, producing a barebones output without any unnecessary formatting:

mysql -sN ...
Copy after login
Copy after login

The above is the detailed content of How to Suppress Header Output for a Specific SQL Statement in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template