There are times when we want to display data based on multiple conditions placed on the database search. This example shows how to do just that.
Given a database table named "suppliers", we would like to load the table with a specific subset of records based on the following SQL statement:
SELECT suppliers.supplier_id,suppliers.supplier_name,suppliers.city,suppliers.state FROM suppliers WHERE (state = "California" AND supplier_id != 900) OR (supplieer_id = 100)
If you look under the Java tab, you'll see how we replicate these multiple criteria in our query.
First, we have in our database the following table of complete data:
|700||Dole Food Company||Westlake Village||California|
|900||Electronic Arts||Redwood City||California|
What displays in our live example is the subset of records based on our query. This query returns all suppliers that are in the state of California but do not have a supplier_id equal to 900. The query will also return all suppliers whose supplier_id is equal to 100, which happens to be Microsoft. The parentheses determine the order that the AND and OR conditions are evaluated.
|Loading data from server|