Now that you understand how conditions are grouped together and evaluated, it’s time to take a look at the different elements that make up a condition. A condition is comprised of one or more expressions along with one or more operators. Examples of expressions include:
Examples of operators include:
The following sections explore many of the common condition types that use different combinations of the preceeding expression and operator types. Equality/Inequality ConditionsMost of the conditions found in a WHERE clause will be equality conditions used to join data sets together or to isolate specific values. You have already encountered these types of conditions numerous times in previous examples, including: s.supplier_id = p.supplier_id s.name = 'Acme Industries' supplier_id = (SELECT supplier_id All three conditions are comprised of a column expression followed by a comparison operator (=) followed by another expression. The conditions differ in the type of expression on the right side of the comparison operator. The first example compares one column to another, the second example compares a column to a literal, and the third example compares a column to the value returned by a subquery. You can also build conditions that use the inequality comparison operator (!=). In a previous example, the NOT operator was used to find information about parts supplied by every supplier other than Acme Industries and Tilton Enterprises. Using the != operator rather than using NOT makes the query easier to understand and removes the need for the OR operator: SELECT p.part_nbr, p.name, p.supplier_id, p.status, p.inventory_qty, While this is an improvement over the previous version, the next section shows an even cleaner way to represent the same logic.
blog comments powered by Disqus |