Querying a MySQL Database

So far, we’ve created a MySQL database and tables, populated them with data, and added indexes to make them fast to search. Now it’s time to look at how these searches are performed, and the various commands and qualifiers available.

SELECT command is used to extract data from a table. In
that section, I used its simplest form to select all data and display it—something you will never want to do on anything but the smallest tables, because all the data will scroll by at an unreadable pace. Alternatively, on Unix/Linux computers, you can tell MySQL to page output a screen at a time by issuing the command:
pager less;

This pipes output to the less program. To restore standard output and turn paging off, you can issue this command:
nopager;

Let’s now examine SELECT in more detail. The basic syntax is:
SELECT something FROM tablename;

Two different SELECT statements:

SELECT author,title FROM classics;
SELECT title,isbn FROM classics;

Leave a Reply

Your email address will not be published. Required fields are marked *