Suppressing Column Headings in Query Output

1.26.1 Problem

You don't want to include column headings in query output.

1.26.2 Solution

Turn column headings off with the appropriate command-line option. Normally this is -N or --skip-column-names, but you can use -ss instead.

1.26.3 Discussion

Tab-delimited format is convenient for generating datafiles that you can import into other programs. However, the first row of output for each query lists the column headings by default, which may not always be what you want. Suppose you have a program named summarize the produces various descriptive statistics for a column of numbers. If you're producing output from mysql to be used with this program, you wouldn't want the header row because it would throw off the results. That is, if you ran a command like this, the output would be inaccurate because summarize would count the column heading:

% mysql -e "SELECT arms FROM limbs" cookbook | summarize

To create output that contains only data values, suppress the column header row with the -N (or --skip-column-names) option:

% mysql -N -e "SELECT arms FROM limbs" cookbook | summarize

-N and --skip-column-names were introduced in MySQL 3.22.20. For older versions, you can achieve the same effect by specifying the "silent" option (-s or --silent) twice:

% mysql -ss -e "SELECT arms FROM limbs" cookbook | summarize

Under Unix, another alternative is to use tail to skip the first line:

% mysql -e "SELECT arms FROM limbs" cookbook | tail +2 | summarize

Using the mysql Client Program

Writing MySQL-Based Programs

Record Selection Techniques

Working with Strings

Working with Dates and Times

Sorting Query Results

Generating Summaries

Modifying Tables with ALTER TABLE

Obtaining and Using Metadata

Importing and Exporting Data

Generating and Using Sequences

Using Multiple Tables

Statistical Techniques

Handling Duplicates

Performing Transactions

Introduction to MySQL on the Web

Incorporating Query Resultsinto Web Pages

Processing Web Input with MySQL

Using MySQL-Based Web Session Management

Appendix A. Obtaining MySQL Software

Appendix B. JSP and Tomcat Primer

Appendix C. References



MySQL Cookbook
MySQL Cookbook
ISBN: 059652708X
EAN: 2147483647
Year: 2005
Pages: 412
Authors: Paul DuBois

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net