Team Fly 

Page 37

1 row created.

SQL> insert into state (state_cd, state_name) values ('FL','Florida');
1 row created.

SQL> insert into state (state_cd, state_name) values ('MN','Maine');
1 row created.

select

As mentioned earlier, the select statement is used to retrieve data from the database. This is the commonest SQL statement you will use. The five basic parts of the SQL statement are as follows:

Image First is the keyword select followed by what you want to retrieve from the database. The names of the columns to be retrieved are listed here. The select command is mandatory.

Image The word from is the next part of the SQL statement. Reference to the object that the data is being retrieved from is made here. This is usually a table name. The from command is mandatory.

Image As mentioned before, a conditional statement is optional for select statements. The word where followed by the conditions would be the next part of the SQL statement. See Critical Skill 2.3 for more details on the where clause.

Image A group by statement is another optional component of the select statement. This topic will be covered in more detail in Critical Skill 2.8 once we have had the opportunity to discuss functions.

Image The final component of a select statement is the order by statement. This will also be discussed in more detail later on in this chapter. This is an optional component, which will sort the results of the query before they are presented back to you.

Let's issue our first select statement against the state table we just populated in the insert command examples:

SQL> select *
  2  from   state;

ST STATE_NAME
-- ------------------------------
AZ Arizona
NJ New Jersey
CA California
TX Texas
Team Fly 
0056