There are 5 articles on this title. You are reading the article ranked and rated #1 by Helium's members.
SQL or Structured Query Language is an ANSI standard for manipulating and accessing database systems. SQL can retrieve and update data in the database in different ways. Though SQL is a standard, some SQL database programs have proprietary additions to the basic SQL commands.
One of the most used SQL command is the SELECT statement and being the only DML statement that does not do any data manipulation. Together with INSERT/INSERT INTO, UPDATE and DELETE statements, SELECT statement is among the Data Manipulation Language (DML) that form part of SQL commands (the other half being Data Definition Language or DDL).
The complete structure of the SELECT statement is actually a very complex one. Below shows the complete list of clauses that make up a SELECT statement:
SELECT Clause
INTO Clause
FROM Clause
WHERE Clause
GROUP BY Clause
HAVING Clause
UNION Clause
ORDER BY Clause
COMPUTE Clause
FOR Clause
OPTION Clause
PARTS OF THE SELECT STATEMENT
=============================
The basic SELECT statement is broken down into the following parts:
SELECT select_list
[INTO new_table_name]
FROM table_list
[WHERE search_conditions]
[GROUP BY group_by_list]
[HAVING search_conditions]
[ORDER BY order_list [ASC | DESC] ]
As we go along, we will make use of the following set of tables:
Table name : Customers
CustID CustName Contact
-
0001 AJ Chemicals Pitt
0002 M.A. Pharma Jolie
0003 ABC Drug Store Aniston
0004 Kline Drugs Cruise
Table name : Orders
OrderNo CustID Amount
-
00011 0001 153.33
00012 0001 45.00
00013 0004 102.22
00014 0002 14.00
00015 0004 52.00
00016 0003 589.00
SELECT CLAUSE
=============
This part of the Select statement specifies the columns to be returned by the query. It also accepts arguments that define the population of data you want to display. Common arguments used are ALL (which is the default value and is commonly not actually specified), DISTINCT (filters the result to remove repeating data) and TOP (returns only the top n rows of the resulting population).
Basic syntax : SELECT [ALL | DISTINCT] [TOP n]
Example/s : SELECT OrderNo, CustID
SELECT DISTINCT *
SELECT TOP 5 CustID, CustName
Result : The select clause alone would not return anything it has to be combined with at least the WHERE clause so it could be functional.
INTO CLAUSE
===========
This clause simply creates a new table and inserts the resulting
Below are the top articles rated and ranked by Helium members on:
by bluephin
SQL or Structured Query Language is an ANSI standard for manipulating and accessing database systems. SQL can retriev... read more
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
by Ray Cook
SQL (Structured Query Language, pronounced SEQUEL) has been around now for about 30 years. SQL provides a n English-... read more
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
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 now!
Cast your vote!
Click for your side. Must be logged in.
Featured Partner
Why Tuesday is a nonprofit, nonpartisan organization that was founded in 2005. Its goal is to raise awareness about t...more
hide