Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Usage » Queries: Selecting Data from a Table » Query overview

Querying and the SELECT statement Next Page

SQL queries


In this manual, SELECT statements and other SQL statements appear with each clause on a separate row, and with the SQL keywords in uppercase. This is not a requirement. You can enter SQL keywords in any case, and you can break lines at any point.

Keywords and line breaks

For example, the following SELECT statement finds the first and last names of contacts living in California from the Contacts table.

SELECT GivenName, Surname
FROM Contacts
WHERE State = 'CA'

It is equally valid, though not as readable, to enter this statement as follows:

SELECT GivenName,
Surname from Contacts
WHERE State
 = 'CA'
Case sensitivity of strings and identifiers

Identifiers (that is, table names, column names, and so on) are case insensitive in SQL Anywhere databases.

Strings are case insensitive by default, so that 'CA', 'ca', 'cA', and 'Ca' are equivalent, but if you create a database as case sensitive then the case of strings is significant. The SQL Anywhere sample database is case insensitive.

For more information on creating databases, see Creating a database, or Initialization utility (dbinit).

For more information about case sensitivity, see Case sensitivity.

Qualifying identifiers

You can qualify the names of database identifiers if there is ambiguity about which object is being referred to. For example, the SQL Anywhere sample database contains several tables with a column called City, so you may have to qualify references to City with the name of the table. In a larger database you may also have to use the name of the owner of the table to identify the table.

SELECT Contacts.City
FROM Contacts
WHERE State = 'CA'

Since the examples in this chapter involve single-table queries, column names in syntax models and examples are usually not qualified with the names of the tables or owners to which they belong.

These elements are left out for readability; it is never wrong to include qualifiers.

The remaining sections in this chapter analyze the syntax of the SELECT statement in more detail.

Row order in the result set

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 want to retrieve rows in a particular order, you must specify the order in the query.