[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
        Sorts query results based on data in column(s).  Each <order_item> must
correspond to a column in the query results and can be:

        .       A field in a FROM database that is also a <select_item> in the main
SELECT clause (not in a subquery)

        .       A numeric expression indicating the location of the column in the
result table. (The leftmost column is number 1.)

        DESC orders query results in descending order according to the
<order_item(s)>.  ASC specifies ascending order for query results and is
default.

+---------------------------------+
|            Examples             |
+---------------------------------+
Display all companies in the CUSTOMER database (one field from one
database) on the screen.

SELECT customer.company ;
        FROM customer

Display three fields from two databases and join the two databases based
on the CUST_ID field.  Use local aliases for both databases.

SELECT a.company, b.date, b.amount ;
        FROM customer a, payments b ;
        WHERE a.cust_id = b.cust_id

Display only records with unique data in the specified fields.

SELECT DISTINCT a.cust_id, b.date, b.amount ;
        FROM customer a, payments b ;
        WHERE a.cust_id = b.cust_id

Display several fields from CUSTOMER in ascending order by STATE, ZIP
and COMPANY.

SELECT state, zip, company, cust_id ;
        FROM customer ;
        ORDER BY state, zip, company

Store fields from two databases in a third database.

SELECT a.cust_id, a.company, b.po ;
        FROM customer a, invoice b ;
        WHERE a.cust_id = b.cust_id ;
        INTO TABLE c:\cust_po.dbf

Display only records having an invoice date before 10/15/90.

SELECT a.cust_id, a.company, b.po ;
        FROM customer a, invoice b ;
        WHERE (a.cust_id = b.cust_id) AND (b.inv_date < {10/15/90})

Display all companies from the CUSTOMER database with a zip code that
matches a zip code in the INVOICE database.

SELECT company FROM customer a WHERE ;
        EXISTS (SELECT * FROM invoice b WHERE a.zip = b.zip)

Display all records from the CUSTOMER database having a company name
that begins with a capital 'C' and is an unknown length.

SELECT * FROM customer a WHERE a.company LIKE 'C%'

Display all records from the CUSTOMER database having a state that
begins with a capital 'N' and is followed by one unknown character.

SELECT * FROM customer a WHERE a.state LIKE 'N_'

Display all records from CUSTOMER with a tax rate that is lower than any
tax rates for Michigan customers.

SELECT * FROM customer a WHERE a.taxrate < ANY ;
        (SELECT taxrate from customer WHERE state = "MI")

Display all cities in CUSTOMER in upper-case and name the output column
CityList.

SELECT UPPER(city) AS CityList FROM customer

-----------------------------------

See Also:  CREATE QUERY, CREATE TABLE - SQL, INSERT - SQL, MODIFY QUERY,
SET ANSI, SET PATH, .  SQL Cursors, SQL, _TALLY

-----------------------------------

See Also: CREATE QUERY CREATE TABLE - SQL INSERT - SQL MODIFY QUERY
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson