Where Knowledge Rules

Computers & Technology:

Software

Get a Widget for this title

Retrieving data with SQL queries: An introduction

Before we dive into the basics of SQL it is pertinent to give a little background on it's origins. SQL was originally coined SEQUEL by IBM in about 1975. It stands for Structured English QUEry Language. At the time, IBM was researching the commercial viability of a relational database system, based on the work of Dr E. Codd and his seminal paper on the relational model published in 1970. SQL is still often pronounced 'see-quel' even today, although the more common term now is 'es-que-el.'

There are many relational database systems now available. The most well known arguably being: Microsoft SQL Server, Oracle, MySql and PostgreSQL. Each system has it's own proprietry implementation of the SQL language. But they all support the SQL99 standard at a minimum.The latest standard at the time of writing is SQL 2006. Each vendor also supplies a command line or GUI client into which SQL queries can be typed and executed against the data stored in the database. Check your documentation for how to use it.

The most basic of SQL Queries is the single select statement. Before we see how to create one and see what it does, it is helpful to describe a database table against which we can work.

tbName
dbNameId dbFirstName dbLastName dbMiddleName
1 John Smith Andrew
2 John Doe NULL
3 Susan Wells Alice
4 Denise Taylor Trudy

The table is a convenient way of representing a set of tuples (rows) in a relation (table). The first column is the key that uniquely identifies each tuple, known as the Primary Key. The other columns are the attributes of each tuple. It is possible for an attribute to be unknown, John Doe's middle name for example is unknown. Unknown attributes are represented as 'NULL' in relational databases.

You can create this table in your database using the following SQL.

CREATE TABLE tbName
(
dbNameId int identity(1,1) Primary Key,
dbFirstName varchar(32) NOT NULL,
dbLastName varchar(32) NOT NULL,
dbNiddleName varchar(32) NULL
)

You can then populate the table with data using INSERT statements.

INSERT INTO tbName (dbFirstName, dbLastName, dbMiddleName)
VALUES('John', 'Smith', 'Andrew')

INSERT INTO tbName (dbFirstName, dbLastName, dbMiddleName)
VALUES('John', 'Doe', NULL)

INSERT INTO tbName (dbFirstName, dbLastName, dbMiddleName)
VALUES('Susan', 'Wells', 'Alice')

INSERT INTO tbName (dbFirstName, dbLastName, dbMiddleName)
VALUES('Denise', 'Taylor', 'Trudy')

To retrieve all the rows from the table, or more correctly, retrieve all the attributes of each tuple in the tbName relation. We use the


Below are the top articles rated and ranked by Helium members on:

Retrieving data with SQL queries: An introduction

  • 1 of 6

    by Ray Cook

    SQL (Structured Query Language, pronounced SEQUEL) has been around now for about 30 years. SQL provides a n English-like

    read more

  • 2 of 6

    by Joseph Love

    Throughout 20+ years in the Information field, I've taught several developers how to interact with a database. Although

    read more

  • 3 of 6

    by Raj Kumar

    The most common SQL command is SELECT statement which falls under data manipulation language (DML) group of statements.

    read more

  • 4 of 6

    by bluephin

    SQL or Structured Query Language is an ANSI standard for manipulating and accessing database systems. SQL can retrieve and

    read more

  • 5 of 6

    by Holly Styles

    Before we dive into the basics of SQL it is pertinent to give a little background on it's origins. SQL was originally coined

    read more

View All Articles on:
Retrieving data with SQL queries: An introduction

Add your voice

Know something about Retrieving data with SQL queries: An introduction?
We want to hear your view. Write_penWrite now!

Helium Debate

Cast your vote!

Will Internet Explorer 8 solve Microsoft's Web browser problems?

Click for your side.

90554

Featured Partner

The Sunlight Foundation

Founded in January 2006, the mission of the Sunlight Foundation is to strengthen the relationship between lawmakers a...more

What is Helium? | Buy Web Content | Contact Us | Privacy | User agreement | DMCA | User Tools | Help | Community | Helium’s Official Blog | Link to Helium

Helium, Inc.
200 Brickstone Square Andover, MA 01810 USA