


Use the ALL predicate to retrieve only those records in the main query that satisfy the comparison with all records retrieved in the subquery. The following example returns all products whose unit price is greater than that of any product sold at a discount of 25 percent or more: SELECT * FROM Products Use the ANY or SOME predicate, which are synonymous, to retrieve records in the main query that satisfy the comparison with any records retrieved in the subquery. In a subquery, you use a SELECT statement to provide a set of one or more specific values to evaluate in the WHERE or HAVING clause expression. You can use a subquery instead of an expression in the field list of a SELECT statement or in a WHERE or HAVING clause. You can use three forms of syntax to create a subquery:Ĭomparison ( sqlstatement)Īn expression and a comparison operator that compares the expression with the results of the subquery.Īn expression for which the result set of the subquery is searched.Ī SELECT statement, following the same format and rules as any other SELECT statement.
#Microsoft access queries update
Additional InformationĬlick here to find an interesting solution using the LIKE condition to exclude records that contain a wildcard character.A subquery is a SELECT statement nested inside a SELECT, SELECT…INTO, INSERT…INTO, DELETE, or UPDATE statement or inside another subquery. The SQL for the query above is: SELECT Sample.PhNo FROM Sampleīy separating the NOT LIKE conditions with the AND operator, we are able to exclude all three types of phone numbers from our results. We can write a query using the NOT LIKE condition as follows: How can I do this?Īnswer: You can do this by using the NOT LIKE condition.įor example, we have a table called Sample that contains phone numbers within a field called PhNo.

Question: In Microsoft Access, I'm trying to create a query that returns phone numbers, but excludes any phone numbers that start with 713612, 713312, or 281999. In this example, we are looking for all company names that do not start with "b". Here is an example of how you'd use the NOT LIKE condition in a query: Result: all values that are not 2 characters in length that start with b and where the second character is a number

Result: all values that are not 2 characters in length starting with b Result: all values that do not end with b Result: all values that do not start with b You can also combine the LIKE condition with the NOT operator. Combining the LIKE condition with the NOT operator In this example, we are looking for all company names that start with "b". Here is an example of how you'd use the LIKE condition in a query: Result: all values that start with b and are 2 characters in length where the second character is a number Result: all values that start with b and are 2 characters in length The patterns that you can choose from are: WildcardĪllows you to match any string of any length (including zero length)Īllows you to match on a single characterĪllows you to match on a single numeric digit The LIKE condition can be used in any valid SQL statement - select, insert, update, or delete. This allows you to perform pattern matching. The LIKE condition allows you to use wildcards in the where clause of a SQL statement in Access 2003/XP/2000/97. See solution in other versions of Access:
