Home > Database > Mysql Tutorial > body text

How to Suppress Column Headers in MySQL Queries?

Linda Hamilton
Release: 2024-11-16 13:16:03
Original
629 people have browsed it

How to Suppress Column Headers in MySQL Queries?

Suppressing Column Headers in a SQL Query

In database operations, presenting query results with column headers provides context for the data displayed. However, there may be scenarios where suppressing these headers is desirable. This question addresses the possibility of disabling column headers for a specific SQL statement while executing multiple queries in batch using the MySQL command-line binary.

Solution

To omit column headers in a single SQL statement, invoking MySQL with the -N (alias for --skip-column-names) option is the key. The following command exemplifies this usage:

mysql -N ...
Copy after login

Consider the following example:

mysql -N ...
use testdb;
select * from names;
Copy after login

This command will produce results without the column headers:

+------+-------+
|    1 | pete  |
|    2 | john  |
|    3 | mike  |
+------+-------+
3 rows in set (0.00 sec)
Copy after login

Furthermore, to remove the grid (vertical and horizontal lines) surrounding the results, the -s (--silent) option can be employed. This will separate columns with a TAB character:

mysql -s ...
use testdb;
select * from names;

id  name
1   pete
2   john
3   mike
Copy after login

Finally, to display data without headers or grid, simply use both -s and -N.

mysql -sN ...
Copy after login

The above is the detailed content of How to Suppress Column Headers in MySQL Queries?. 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