To fetch the records using select statements

There are some useful command to help fetch the records from mysql database.

Retrieving Individual Columns
If we want to execute the following SQL statement using mysql command and the output is shown as.
mysql> select first_name from students;

img 1.gif

Retrieving Multiple Columns
Now we will try to a another simple select statement, this time on the products table. We can retrieve the values from two columns in the same query by specifying a list of columns after the SELECT keyword, separating them with a comma.

mysql> select last_name,street from students;

img 2.gif

Retrieving All Columns
When we have to retrieve the data from every column in a table, we do not need to specify each column name after the SELECT keyword. Use the asterisk character (*) in place of a column list in a SELECT statement to instruct MySQL to return every column from the specified table.

The following query retrieves every column and row from the products table.

mysql> select * from students;

img 5.gif

Note : The output produced is exactly the same, as if we had specified each column in the query by name, like this.

mysql> SELECT code, name, weight, price FROM products;

img 3.gif