Business Database Technology (2nd Edition) by Shouhong Wang;Hai Wang;

Business Database Technology (2nd Edition) by Shouhong Wang;Hai Wang;

Author:Shouhong Wang;Hai Wang;
Language: eng
Format: epub
Publisher: Universal Publishers


Listing 6.30. An Example of Query with Integration of Clauses

6.14. UNION Operator

The UNION operator connects two SELECT statements to include the query results of the first SELECT statement and the second SELECT statement. As an illustrative example, the query in Listing 6.31 is to “list the course ID and course enrollment for each course that has enrollment greater than 35, or the student name and student ID for each student who enrolled after 2019.” In fact, the UNION operator is a kind of OR operator between the two SELECT statements. This example is merely to demonstrate how the UNION operator works. As shown in this example, if the attributes listed in the two SELECT statements are not comparable, the query result of the UNION operator would not be particularly meaningful. As the UNION operator often introduces confusion, it is not recommended for beginners.

SELECT CourseID AS Name, CourseEnrollment AS Data

FROM tblCourse

WHERE CourseEnrollment>35

UNION

SELECT StudentName AS Name, StudentID AS Data

FROM tblStudent

WHERE StudentEnrolYear>2019;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.