Since "Joe" matched the NOT statement, it's excluded from the results. The one difference is that the "Joe" record is excluded. Notice how the results look similar to the query for the IN statement. The above statement says "give me all records that have city values of Miami and Atlanta but exclude any of these records that have a first name of Joe." The result record set is the following. WHERE City IN (‘Miami', ‘Atlanta') AND First_name NOT IN (‘joe') The following query gives you an example of the NOT operator. SQL has a NOT operator that excludes those records while still including the others that match the original IN query. Suppose you want to include records with city values of Atlanta and Miami, but you want to exclude records where the user's first name is Joe. You sometimes need to exclude records from your results. So far, we've only created SQL statements where you want to include records. You might return 1000 records but want to exclude some records within the data set. The following result is displayed by SQL. The result of both statements is the same. The following SQL statement does the same as the above statement. You can combine these OR statements into an IN statement. Imagine you have 10 of these cities you need to find. You could write an OR statement that looks like the following. Suppose you want to return values for customers that are only in Atlanta and Miami. The IN condition lists values in parenthesis, and it's better than working with multiple OR conditions. The IN condition lets you set a list of values that must match values in your tables. LIKE uses wildcards, which are used to query similar values, but IN and NOT return precise record sets based on specific values. Some SQL keywords that help you build complex statements include IN, NOT, and LIKE. These statements get complex when you have several business requirements that must be used to return a data set that helps businesses make decisions. As a coder, you gather business rules that then decide how to structure your SQL statements to ensure that returned results are accurate for reports and applications. SQL gets complex when you have multiple business rules that run how you return record sets.
0 Comments
Leave a Reply. |