WHERE Clause (SQL Only)

See AlsovbhowSQLWHERESee                 ExamplevbhowSQLWHEREEx>Low

Description

You can use WHERE to determine which records from the tables listed in the FROM clause will appear in the results of the SELECT statement.  Records are selected according to the conditions listed in the WHERE clause.

For example, you can select all employees in the Sales department (WHERE Dept = 'Sales') or all customers between the ages of 18 and 30 (WHERE Age BETWEEN 18 And 30).

Notes

         WHERE is optional, but when included follows FROM.  If you don't include WHERE, all records are selected.

         If you specify more than one table in your query with the FROM clause, and do not include a WHERE clause, Visual Basic will return a "cartesian product" of the tables. In other words, your query will contain all records from each additional table for each record of the first table. See JOIN for more information.

         WHERE is similar to HAVING.  WHERE determines which records are selected.  Similarly, once records are grouped with GROUP BY, HAVING determines which records are returned.

         Use the WHERE clause to eliminate rows you don't want grouped by a GROUP BY clause.

         Use various expressions to determine which records the SQL statement returns.  For example, the following SQL statement selects all books which were published after 1991:

  SELECT [Year Published], Title
  FROM Titles
  WHERE [Year Published] > 1991

 

         When you enter a field name that contains a space or punctuation, surround the name with brackets:

  SELECT [Product ID], [Units In Stock]
  FROM Products
  WHERE [Units In Stock] <= [Reorder Level]