This really is a how-to for beginners in MYSQL.
One of the important things to remember, is that case, for the most part, is ignored in MYSQL. So SELECT is the same as select.
It is also important to note that every command must be followed by the semi-colon, just as in the examples that follow.
Opening your database.
At the mysql prompt, the command show will help you get started.
QUOTE
mysql> show databases;
This will return all of the databases in mysql. To open one of the databases, try the following:
QUOTE
mysql> use DATABASE;
With the database open, you can look at all of the tables that currently exist.
QUOTE
mysql> show TABLES;
You won't have to 'use' or 'select' the table. The select command actually allows you to select the column within the given TABLE.
QUOTE
mysql> select first,last from TABLE;
This will select the column labeled first & the column labeled last from the given TABLE. You can use an * to select every column.
QUOTE
mysql> select * from TABLE;
If you don't care for the "side-to-side" look, you can get a column: value look using back-slash G.
QUOTE
mysql> select first,last from TABLE\G
You can also help make your output easier to read using limit.
QUOTE
mysql> select first,last from TABLE limit 5\G
Add order to your output using the order by option.
QUOTE
mysql> select first,last from TABLE limit 5 order by first\G
The data that we have retrieved so far was always displayed in the order in which it was stored in the table. Here I will show you how to filter the output results by asending or descending values. This will work with both alphabetical & numerical values.
QUOTE
mysql> select first,last from TABLE limit 5 order by first ASC\G
mysql> select first,last from TABLE limit 5 order by first DESC\G
This tutorial should get you well on your way to using the select statement in MYSQL.