Channel Button

There are 5 articles on this title. You are reading the article ranked and rated #5 by Helium's members.

Computers & Technology   >

Software & Web Development

Retrieving data with SQL queries: An introduction

by Meera

The most common query on a database is to retrieve data from the database tables. In SQL, the SELECT statement performs this task. This article describes the basic structure of a SELECT statement, and how to use it to retrieve specific rows and columns from a table, and group and filter them.

A SELECT statement can be broken down into numerous elements, each beginning with a keyword. The basic elements of a SELECT statement are as follows:

SELECT
FROM
WHERE
ORDER BY

Based on the above keywords, a basic SELECT statement may look like

SELECT FROM WHERE ORDER BY

where, the angular brackets (< >) denote the variables specific to the query being performed. Now let us examine the SELECT statement more closely.

Throughout this article, the following sample from the Employee' table of the MS Access sample database NorthWind', is used for examples:

ID LastName FirstName Title City Country ReportsTo
-
1 Davolio Nancy Sales Representative Seattle USA Fuller, Andrew
2 Fuller Andrew Vice President, Sales Tacoma USA
3 Leverling Janet Sales Representative Kirkland USA Fuller, Andrew
4 Peacock Margaret Sales Representative Redmond USA Fuller, Andrew
5 Buchanan Steven Sales Manager London UK Fuller, Andrew
6 Suyama Michael Sales Representative London UK Buchanan, Steven
7 King Robert Sales Representative London UK Buchanan, Steven
8 Callahan Laura Sales Coordinator Seattle USA Fuller, Andrew
9 Dodsworth Anne Sales Representative London UK Buchanan, Steven

The SELECT ... FROM Clause
-

The most basic SELECT statement specifies what columns have to be retrieved from what table(s). For example, to retrieve all the first and last names from the Employee' table, write the query as

SELECT FirstName, LastName FROM Employee

This query returns the values

FirstName LastName
-
Nancy Davolio
Andrew Fuller
Janet Leverling
Margaret Peacock
Steven Buchanan
Michael Suyama
Robert King
Laura Callahan
Anne Dodsworth

In the result set, the columns will be in the same order as in the query. In the above example, the result displays FirstName before LastName, even though the table stores FirstName after LastName.

Few useful symbols and keywords:
To retrieve all the columns from the table, use the


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

Retrieving data with SQL queries: An introduction

  • 1 of 5

    by bluephin

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

  • 2 of 5

    by Joseph Love

    In my 20+ years in I.T., I've taught several developers how to interact with a database. Although I could teach a 3 w... read more

  • 3 of 5

    by Ray Cook

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

  • 4 of 5

    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... read more

  • 5 of 5

    by Meera

    The most common query on a database is to retrieve data from the database tables. In SQL, the SELECT statement perfor... read more

Add your voice

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

What is Helium? | User Guide | Community | Link to Helium | Privacy | User agreement | DMCA

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