Paradox Community
Search:

 Welcome |  What is Paradox |  Paradox Folk |  Paradox Solutions |
 Interactive Paradox |  Paradox Programming |  Internet/Intranet Development |
 Support Options |  Classified Ads |  Wish List |  Submissions 


Interactive Paradox Articles  |  Beyond Help Articles  |  Tips & Tricks Articles  


Local SQL Part 2
The SQL SELECT Statement
© 2001 Lawrence G. DiGiovanni
Digico, Inc.
www.digicoinc.com

Preface

Local SQL is a very powerful yet commonly underutilized tool that is provided with Paradox® (as part of the Borland® Database Engine). It exposes the power and flexibility of the SQL sublanguage to both Paradox developers as well as interactive end-users.

This is the second in a planned series of articles on using Local SQL with Paradox/BDE™ applications. This article introduces the SQL SELECT statement, its clauses, arguments and predicates, and describes how it can be used to query single tables.

If you haven't reviewed Local SQL Part 1, you may wish to do so before continuing.


Introduction

The SQL SELECT statement is probably the most commonly used statement type in the SQL sublanguage. Its purpose is to define a result set (i.e., an ANSWER table) consisting of specific rows and columns of a table (or tables, as we'll later explore) in a database.


Parts of a SELECT

A SQL SELECT statement consists of the word SELECT, followed by a series of optional and required clauses, predicates, and arguments. The order of clauses is defined below, and clauses (when used) must be used in that order. White space (except that which separates clauses, expressions, etc.) is ignored. Also, SQL is not case-sensitive with regard to clauses, column names, table names, etc, except when comparing values. The general form of the SELECT statement is:

SELECT <column-list>
  FROM <table-list>
 WHERE <condition-list>
GROUP BY <column-list>
HAVING <condition-list>
ORDER BY <column-list>
The SELECT clause and its <column-list> are required. <column-list> is a comma-separated list of table columns or expressions involving literal values and/or columns.

The FROM clause and its <table-list> are required. <table-list>> is a comma-separated list of tables. Table columns in the <column-list> of the SELECT statement must all exist within the tables in <table-list>.

The WHERE clause is optional. <condition-list> is a list of conditions, which are logical expressions involving table columns, literal values, and SQL functions. The WHERE clause is used to restrict the result set to only those rows meeting the criteria set forth in the <condition-list>. Conditions may be combined using AND, OR and logically grouped using parenthesis. The WHERE clause is evaluated for each row of the table being queried. When the WHERE clause is omitted, all rows of the table are included in the result set.

The GROUP BY clause is optional. <column-list> is a list of columns which define groupings of rows in the result set. This clause will be explored in detail in a future article.

The HAVING clause is optional and may only be used following a GROUP BY clause. <condition-list> is a list of conditions involving groupings of data and determine whether or not a given group will be included in the result set. This clause will be explored in detail in a future article.

The ORDER BY clause is optional. <column-list> is a list of columns which determine the sort order of the result set. Each column may optionally be modified by the predicate ASC or DESC, to indicate ASCending or DESCending sort order, respectively. The default is ASC, so the predicate need not be used to obtain the ascending sort order. Note that using the ORDER BY clause is the *only way* to guarantee the sort order of a result set. When no ORDER BY clause is specified, the order of the rows of the result set must be considered random.

The above description purposely omitted a number of clauses and predicates of a SQL statement, many of which will be discussed in a future article.


Summary

The SQL SELECT statement is a commonly used statement type in SQL. It defines a result set (i.e., an ANSWER table) consisting of specific rows and columns of a table.

In future articles, we'll explore each of the clauses of the SELECT statement and see how this powerful and flexible statement can be used to perform a wide variety of database functions.


Local SQL Part 3


Discussion of this article


 Feedback |  Paradox Day |  Who Uses Paradox |  I Use Paradox |  Downloads 


 The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation.
 Paradox is a registered trademark of Corel Corporation.


 Modified: 15 May 2003
 Terms of Use / Legal Disclaimer


 Copyright © 2001- 2003 Paradox Community. All rights reserved. 
 Company and product names are trademarks or registered trademarks of their respective companies. 
 Authors hold the copyrights to their own works. Please contact the author of any article for details.