ColdFusion supports INNER JOINs between two tables, as the following example shows. This
operation is the most common type of join.
SELECT Dog_ID, Breed_ID
FROM Dogs, Breed
WHERE Dogs.Dog_ID = Breed.Dog_ID;
Using unions
The UNION operator lets you combine the results of two or more SELECT expressions into a
single record set. The original tables must have the same number of columns, and corresponding
columns must be UNION-compatible data types. Columns are UNION-compatible data types if
they meet one of the following conditions:
•
The same data type; for example, both Tinyint
•
Both Numeric; for example, Tinyint, Smallint, Integer, Bigint, Double, Float, Real, Decimal,
or Numeric
•
Both Characters; for example, Char, Varchar, or LongVarchar
•
Both Dates; for example, Time, TimeStamp, or Date
Note: Query Of Queries does not support ODBC-formatted dates and times.
Syntax
select_expression = select_expression UNION [ALL] select_expression
Example
This example uses the following tables:
Table1
Type(int)
1
2
3
Table2
ID(int)
3
4
5
To combine Table1 and Table2, use a UNION statement, as follows:
SELECT * FROM Table1
UNION
SELECT * FROM Table2
Name(varchar)
Tennis
Baseball
Football
Sport(varchar)
Football
Volleyball
PingPong
Query of Queries user guide
463
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers