Retrieving Distinct Field Values
Description
A common application requirement is to produce a list of unique field values contained in a table or set of records. The SQL language uses the DISTINCT keyword to produce these lists.
Open the SQL Genie and display its Tables tab.
dim qry as C dim conn as SQL::Connection conn.open("{A5API=Access,FileName='C:\Program Files\a5v8\MDBFiles\Alphasports.mdb',UserName='Admin'}") qry = sql_query_builder(conn)
Click Add Table to display the Add Table dialog.
Select "Customer" and click OK. The SQL window now shows:
SELECT * FROM Customer
Display the Columns tab.
Click the '<<' button to remove the asterisk "*" from the Selected Columns list.
Select "BILL_STATE_REGION" in the Available Columns list and click the >' button. The SQL window now shows:
SELECT [SHIP_STATE_REGION] FROM Customer
Display the Order tab.
Select "BILL_STATE_REGION" in the Available Columns list and click the '>' button. The SQL window now shows:
SELECT [BILL_STATE_REGION] FROM Customer ORDER BY [BILL_STATE_REGION]
Display the Properties tab.
Select the Distinct? check box. The SQL window now shows:
SELECT DISTINCT [BILL_STATE_REGION] FROM Customer ORDER BY [BILL_STATE_REGION]
Click Execute Query.
Click Close to exit the SQL Genie.
Run the next statements to retrieve and display the data.
conn.execute(qry) sql_resultset_preview(conn.ResultSet)
You will see an alphabetized list of unique state values.
Limitations
Desktop applications only.
See Also