Sunday, January 27, 2008

Learning the Basics of SQL - Part One - The SELECT Statement

Let's get straight down to business.

We'll start with the most often used statement:

THE SELECT STATEMENT:

Basic syntax:


SELECT column_name(s)
FROM table_name



--------------------------------------

For example (using the table Products in the previous post):

partialprod









SELECT prod_name



FROM Products

Will return :

prodresults

--------------------------------------

Or we can retrieve multiple columns such as:








SELECT prod_name, prod_price


FROM Products


and you'll get:

prodresult2

--------------------------------------

Or you can use wildcards and retrieve all the columns:






SELECT *
FROM Products

and you'll see:

partialprod

In SQL, spaces don't count, and Enter presses don't either. Meaning that you can type:

SELECT * FROM Products

and get the same results.

Next we will discuss the WHERE clause. Before that, I will post instructions on how to open the database in Microsoft Access and send it SQL queries.

No comments:

Contact Form