From the course: AWS Certified Data Engineer Associate (DEA-C01) Cert Prep

SQL operators

- [Instructor] In this lesson, we'll look at the SQL operators that you can use in where clauses to add sophisticated conditions to your queries. We just saw how you can use the and operator to retrieve rows where more than one condition is true. If you want to retrieve rows where one of multiple conditions are true, you can use the or operator. In this example, we're retrieving the customers who live in Florida or in New York. Finally, we can use not to test for a negative condition. For example, we can retrieve all the customers who don't live in New York. You can use multiple different operators in the same where clause. However, you should include parentheses to ensure the order of precedence. Some other operators you can use in a where clause include greater than, less than, greater than, or equal to, and less than or equal to, and not equal, which is in some engines is less than greater than and others exclamation point equal sign. The between operator selects records that are between a minimum and maximum value. Note that this is inclusive of the specified values, meaning that you can think of between as the same as greater than or equal to, and less than or equal to. The like operator lets you use wild cards in the condition statement. The percent sign is used to represent any number of characters at the beginning or end of a string. In this example, all of the customers with a last name starting with A will be returned. You can also use an underscore as a wild card to represent a single character anywhere in a string. Finally, you can use the in operator to select rows with a column value that matches one of the elements in a list of values. In this example, customers who live in New York, Atlanta or Chicago will be returned. In a relational table, every row has to have a value for every column. But what if that value is missing or unknown? That is where null comes in. A null value signifies that a value for that attribute has not been set. So when you add data to a table and don't specify a value for a column, it is going to be set to null by default. And when you query the table, you can select just the rows with a null value in a column, or just the ones without a null value by using is null or is not null.

Contents