Conditions | Statements sometimes taking out all of the database records may just meet your requirements, but in most cases we usually only need to get a partial record. So how do you design the query? Of course it will be a bit more brain, and this article also deliberately do not want to let you use that what them recordset.
For example, if you're only going to take out P_name records and the names of those records must start with the letter W, you'll need to use the following WHERE clause:
SQL = "Select P_name from the products WHERE p_name like ' w% '"
WHERE keyword followed by the conditions used to filter the data, with the help of these conditions, only to meet a certain standard of data will be queried. In the above example, the result of the query will only get the P_name record with the first name in W.
in the above example, the percent sign (%) means that the query returns a record entry that starts with all the W letters and is followed by any data or even no data. Therefore, in the execution of the above query, West and Willow will be selected from the Products table and stored in the query.
as you can see, as long as you carefully design the SELECT statement, you will be able to limit the amount of information returned in the recordset, and think more often to meet your requirements.
These ah still just grasp the SQL use just started. To help you learn more about the use of complex SELECT statements, let's take a look at the key standard terms: comparison operators, which are often used when you build your own select string to get specific data.
WHERE clause base
the simplest way to start creating a WHERE clause is to use standard comparison symbols, which are <, <=, >, >=, <>, and =. Obviously, you will soon be able to understand the meaning of the following code and the exact results of the operation: SELECT * from the products WHERE p_price >= 199.95
SELECT * FROM Products WHERE P_price <> 19.95
SELECT * from the products WHERE p_version = ' 4 '
Note: Here you will notice that the number 4 in the last example is surrounded by single quotes. The reason is that, in this example, ' 4 ' is a literal type, not a numeric type. Because you put the SELECT statement in quotes to assign it as a value to the variable, you can also use quotes in the statement.
comparison operator
The
comparison operator specifies the range of content that is fetched from the table. You can use them to create filters to narrow the recordset so that it saves only the information you care about under a given task.