SQL - An Introduction

SQL stands for Structured Query Language and is sometimes pronounced as "sequel."  SQL is used to communicate with a database. At its simplest, it is the language that is used to extract, manipulate, and structure data that resides in a relational database management system (RDBMS). In other words, to get an answer from your database, you must ask the question in SQL.

SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database. Some common relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access, Ingres, etc. Although most database systems use SQL, most of them also have their own additional proprietary extensions that are usually only used on their system.

Queries

Four questions to create a query:

  1. What output do you want to see?
  2. What tables are involved?
  3. What do you already know (or what constraints are given)?
  4. How are the tables joined together?

Select Query

The select statement is used to query the database and retrieve selected data that match the criteria that you specify. Here is the format of a simple select statement:

Syntax Example Output
select "column1"
  [,"column2",etc]
  from "tablename"
  [where "condition"];


  [] = optional

select deptno, dname
from dept
where loc = 'New York';

  SELECT ename, job
from emp, dept
where emp.deptno=dept.deptno
and loc = "Dallas";

The column names that follow the select keyword determine which columns will be returned in the results. You can select as many column names that you'd like, or you can use a "*" to select all columns.

The table name that follows the keyword from specifies the table that will be queried to retrieve the desired results.

The where clause (optional) specifies which data values or rows will be returned or displayed, based on the criteria described after the keyword where.

Conditional selections used in the where clause:

= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal to
LIKE use with wildcard characters (* and ?)

 


 

Working in Microsoft Access

  1. Download Access Database

  2. Creating a Query in MS Access

  3. Exercises

 

 


Some Additional SQL Web Resources

Fundamental Microsoft Jet Sql for Access 2000

sqlcourse.com

A Gentle Introduction to SQL