Monday, July 30, 2012

The SELECT Statement Part 1: Single Retrieval Query Statement

     Retrieval of queries are done if you want to gather a data in the database and do something about that data like viewing and updating. The retrieval query used in MySQL is the "SELECT" statement. There are different ways of using the "SELECT" statement. Today we will discuss how to use the "SELECT" statements in single retrieval query statement.

SIMPLE SQL QUERY
     The simple SQL query is using the "SELECT" statement with basic query parts. These parts include these:
   SELECT  <attribute_list>
   FROM    <table_list>
   WHERE   <condition>
     The attribute_list is the list of attribute you would like to retrieve or view, the table_list is the list of table you want to get the attribute from, and the condition is the expression that you wanted to verify first before retrieving the data.
     Here is an example:

ALIASES
     Another way of displaying the attribute is by using aliases. Aliases are used to modify the headings of the attributes displayed in the table. To use Aliases you will need to use the "AS" keyword after the attribute you wanted to rename.
     Here is an example:

UNSPECIFIED WHERE-CLAUSE
     An unspecified where-clause means that you don't need a condition in getting your data. This will result to the display of all possible records in the database.
     Here is an example:

THE USE OF Asterisk(*)
     Asterisk(*) is used if you don't want to specify which attribute would you like to display or use. It would mean that all attributes in that table will be displayed.
     Here is an example:

USE OF DISTINCT
     If you want to display records of the database wherein there is a distinct value, you can use the DISTINCT keyword. To use this just add "DISTINCT" before the attribute you wanted to have a distinction with.
     Here is an example:

     Now these are the basic query retrieval techniques in MySQL. Next time, we will continue on discussing the "SELECT" statement on how to use it in multiple queries and multiple tables.

No comments:

Post a Comment