Retrieving Accurate Data

Be cautious when using the compound operators. Incorrect or incomplete data may be returned if you were using the INTERSECT operator and you used the wrong SELECT statement as the first individual query. In addition, consider whether duplicate records are wanted when using the UNION and UNION ALL operators. What about EXCEPT? Do you need any of the rows that were not returned by the second query? As you can see, the wrong compound query operator or the wrong order of individual queries in a compound query can easily cause misleading data to be returned.

Note

Incomplete data returned by a query qualifies as incorrect data.

Get Sams Teach Yourself SQL in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.