Credits

Sunday, July 31, 2011

Integrate SQL in Your Database Programming

SQL is a powerful language that allows you to create databases and tables and create relationships when necessary.

There are different versions of SQL but in compliance with ANSI standards, there are some major commands that work the same way. Before you start your integration, it is a must that we get oriented with the basics of SQL  commands.



Assume our  Persons table has the following fields and records:

Lastname        Firstname         City
Smith            Will                  Los Angeles City
Jolie              Angelina          New York City
Aniston         Jennifer            New York City
Willis            Bruce              Appleton City

SELECT – is used to return queries. The following are different use of SELECT.

SELECT  * FROM PERSONS

Returns all the fields and their records

Lastname        Firstname         City
Smith              Will                 Los Angeles City
Jolie                Angelina         New York City
Aniston           Jennifer           New York City
Willis              Bruce             Appleton City
[+/-] show/hide




SELECT Lastname FROM Persons
The output shall be:
Lastname
Smith
Jolie
Aniston
Willis

SELECT * FROM Persons where City =”New York City”
This command shall return records that satisfy the condition.

Lastname                 Firstname               City
Jolie                        Angelina                 New York City
Aniston                   Jennifer                   New York City

SELECT Lastname,Firstname FROM Persons ORDER BY Lastname
This shall return all the last name and first names and arrange them by their last name.

Lastname                   Firstname
Aniston                      Jennifer
Jolie                          Angelina
Smith                        Will
Willis                         Bruce

AddThis