Queries

You query or retrieve data from a database with the SQL SELECT statement. The basic query operations in a relational system are selection, projection, and join. The SELECT statement implements all of them.

Projections and restrictions

A projection is a subset of the columns in a table. A restriction (also called selection) is a subset of the rows in a table, based on some conditions.

For example, the following SELECT statement retrieves the names and prices of all products that cost more than fifteen dollars:

SELECT name, unit_price
FROM product
WHERE unit_price > 15 

This query uses both a restriction (WHERE unit_price > 15) and a projection (SELECT name, unit_price)

Joins

A join links the rows in two or more tables by comparing the values in key columns and returning rows that have matching values. For example, you might want to select the order item identification numbers and product identification numbers for all order items for which more than a dozen items were shipped. If you created a join index on sales_order_items.id and product.id, Sybase IQ would use the join to speed up queries like the following:

SELECT sales_order_items.id, product.id
FROM product, sales_order_items
WHERE sales_order_items.quantity > 12