Databases Reference
In-Depth Information
Include nondistinct selection ( UNION performs SELECT DISTINCT by default):
SELECT Column1, Column2 FROM table1_name
UNION ALL
SELECT Column1, Column2 FROM table2_name
EXCEPT and INTERSECT
Select the differences ( EXCEPT ) or common values ( INTERSECT ) between two queries:
SELECT * FROM TableA EXCEPT SELECT * FROM TableB
SELECT * FROM TableA INTERSECT SELECT * FROM TableB
ORDER BY
Order a result set by one or more column values. The default order is ascending. If ordering by more
than one column, each column can have a different order.
SELECT * FROM table_name ORDER BY Column1
SELECT * FROM table_name ORDER BY Column1 DESC, Column2 ASC
COMPUTE (BY)
The COMPUTE and COMPUTE BY clauses generate totals that are appended to the end of an aggregate
query result set. These clauses are not very useful in applications because the aggregated results are not
in relational form and cannot be utilized in a dataset.
SELECT * FROM table_name ORDER BY Column1
SELECT * FROM table_name ORDER BY Column1 DESC, Column2 ASC
FOR Clause
The FOR clause is used with either the XML or BROWSE option in a SELECT statement. However, the
BROWSE and XML options are completely unrelated. FOR XML specifies that the result set is returned
in XML format. FOR BROWSE is used when accessing data through the DB-Library so that rows can be
browsed and updated one row at a time in an optimistic locking environment. There are several require-
ments when using the FOR BROWSE option. For more information consult the SQL Server Books Online
under the topic “Browse Mode.”
SELECT * FROM table_name FOR XML {XML Option}
SELECT * FROM table_name FOR BROWSE
OPTION Clause
The OPTION clause is used in a SELECT statement to provide a query hint that will override the query
optimizer and specify an index or specific join mechanism to be used along with other hint options. As
a rule, this is not a recommended practice but may be useful in rare cases to influence query processing
and performance.
Search WWH ::




Custom Search