ASA Getting Started
Selecting Data from Database Tables
The simplest SELECT statement retrieves all the data in a single table. This SELECT statement has the following syntax:
SELECT * FROM table-name
where table-name should be replaced with the name of the table you are querying. The asterisk (*) is a short form for a list of all columns.
List all products sold by the company
In Interactive SQL, type the following in the SQL Statements pane and press F5 to execute the statement.
SELECT * FROM Product
The SELECT statement retrieves all the rows and columns of the product table, and displays them on the Results tab in the Results pane:
id | name | description | size | color | quantity | unit_price |
---|---|---|---|---|---|---|
300 | Tee Shirt | Tank Top | Small | White | 28 | 9 |
301 | Tee Shirt | V-neck | Medium | Orange | 54 | 14 |
302 | Tee Shirt | Crew Neck | One size fits all | Black | 75 | 14 |
400 | Baseball Cap | Cotton Cap | One size fits all | Black | 112 | 9 |
... | ... | ... | ... | ... | ... | ... |
The Product table contains seven columns. Each column has a name, such as color or id. There is a row for each product that the company sells, and each row has a single value in each column. For example, the product with ID 301 is a Tee Shirt. It is a V-neck style in medium size, and is orange in color.
Table names are case insensitive The table name Product starts with an upper case P, even though the real table name is all lower case. Adaptive Server Anywhere databases can be created as case-sensitive or case-insensitive in their string comparisons, but are always case insensitive in their use of identifiers such as table names and column names.
For information on creating databases, see Creating a database, or The Initialization utility.
SQL keywords are case insensitive You can enter select or Select instead of SELECT. In the documentation, upper case letters are generally used for SQL keywords.
Line breaks are not important You can type the statements all on one line, or break them up by pressing Enter at the end of each line. Some SQL statements, such as the SELECT statement, consist of several parts, called clauses. In many examples, each clause is placed on a separate line for easier reading, so the statement in the example is commonly written as follows in the documentation:
SELECT * FROM product
Row order in the result set is insignificant There is no guarantee of the order in which rows are returned from the database, and no meaning to the order. If you wish to retrieve rows in a particular order, you must specify the order in the query.
For more information, see Ordering query results.
Try querying other tables in the sample database, such as the employee, customer, contact, or sales_order tables.