Teach Yourself SQL

Any problem with SQL can be discussed here.
Post Reply
ELMOHTARF
Posts: 356
Joined: Mon Aug 29, 2005 9:57 am
Contact:

Teach Yourself SQL

Post by ELMOHTARF »

Introduction to the Query:
The SELECT Statement
As you will find, syntax in SQL is quite flexible, although there are rules to follow as in any programming language. A simple query illustrates the basic syntax of an SQL select statement. Pay close attention to the case, spacing, and logical separation of the components of each query by SQL keywords.

SELECT NAME, STARTTERM, ENDTERM
FROM PRESIDENTS
WHERE NAME = 'LINCOLN';

In this example everything is capitalized, but it doesn't have to be. The preceding query would work just as well if it were written like this:

select name, startterm, endterm
from presidents
where name = 'LINCOLN';

Notice that LINCOLN appears in capital letters in both examples. Although actual SQL statements are not case sensitive, references to data in a database are. For instance, many companies store their data in uppercase. In the preceding example, assume that the column name stores its contents in uppercase. Therefore, a query searching for 'Lincoln' in the name column would not find any data to return. Check your implementation and/or company policies for any case requirements.
Take another look at the sample query. Is there something magical in the spacing? Again the answer is no. The following code would work as well:

select name, startterm, endterm from presidents where name = 'LINCOLN';


With My Best Wishes ::::::: Scorpion :::::::::
Post Reply