SQL Queries
Structured Query Language (SQL) is a standard language for accessing and manipulating databases. You use SQL when you work with relational queries in CDM.
You can use SQL statements to perform the following types of database-related tasks:
- Execute queries against the database
- Retrieve data from the database
SQL statements have a specific syntax and require certain information, which can be difficult to understand. When you select what you want to include in a SQL statement in CDM, you can ensure that your statement is structured correctly.
Important: The advanced functionality for Microsoft™ products is beyond the scope of this guide. However, some topics are included for your convenience. For more information, see Microsoft documentation or Microsoft online help.
Keywords, Clauses, and Statements
You can use SQL statements in relational queries in CDM to perform most of the activities that you need to perform in a database.
When you query relational data sources in CDM, you must retrieve data through SELECT statements. If you use SQL statements other than SELECT, such as UPDATE or DELETE, they are reported as errors. Use of a semicolon is not supported.
Note: SQL itself is not case-sensitive. Names can be case-sensitive, and they can contain spaces and other delimiters if they are surrounded by double quotation marks.
The following statement shows the structure of a basic SQL statement:
SELECT VendorName FROM Table_Vendor
Keyword |
Description |
|---|---|
SELECT |
The
Tip: The asterisk (*) is a quick way of selecting all columns in a table. For example:
|
FROM |
The
|
WHERE |
Optional. When used, the
|
Comparison Operators
The WHERE clause can use comparison operators as part of the expression in a relational query in CDM. The result of a WHERE expression is always evaluated to true, false, or unknown.
Operator |
Description |
|---|---|
= |
Equal to |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
<> |
Not equal to |
Logical Operators
The WHERE clause in a SQL statement can use logical operators as part of an expression in a relational query in CDM. Like comparison operators, logical operators evaluate to true, false, or unknown.
Logical Operator |
Description |
|---|---|
AND |
This operator combines two logical conditions. AND requires that each must be met for the record to be included in the result set. When you use the AND and OR operators together, AND has a greater precedence than OR.
In this case, |
OR |
This operator combines two logical conditions. OR requires that any of the conditions must be met for the record to be included in the result set. When you use the AND and OR operators together in an expression, OR has a lesser precedence than AND.
In this case, either |
NOT |
This operator inverts the result of a comparison expression or a logical expression. To be able to return a record in the result set, NOT requires that none of the conditions are met.
In this case, |
Joins and Unions
You can use a SQL statement to create joins and unions between tables in a relational query in CDM.
Query Type |
Description |
|---|---|
JOIN |
You can use a join statement to combine rows from multiple tables. An inner join is the most common, and returns all rows from multiple tables where the join condition is met. An outer join is used to include rows that exist in one table (but not the other). A left outer join preserves rows from the table specified before the join statement. A right outer join preserves rows from the table specified after the join statement. For example, an inner join might look like this:
|
UNION |
You can use a union statement to combine the result sets of two or more
|