Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Combining the AND and OR Conditions Jump to:  
Category: >> Oracle PL/SQL >> Combining the AND and OR Conditions Bookmark and Share

<< lastnext >>

Snippet Name: Combining the AND and OR Conditions

Description: The AND and OR conditions can be combined in a single SQL statement. It can be used in any valid SQL statement - select, insert, update, or delete.

Also see:
» BETWEEN Condition
» LIKE Condition
» OR Condition
» AND Condition
» WHERE Clause - Joins
» WHERE Clause - Conditions
» Having Clause

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 10th, 2009

-- When combining these conditions, it is important to use brackets 
-- so that the database knows what order to evaluate each condition.
 
-- Example #1
 
-- The first example that we'll take a look at an example that 
-- combines the AND and OR conditions.
 
SELECT *
FROM suppliers
WHERE (city = 'New York' AND name = 'IBM')
OR (city = 'Newark');
 
-- This would return all suppliers that reside in New York whose 
-- name is IBM and all suppliers that reside in Newark. The brackets 
-- determine what order the AND and OR conditions are evaluated in.
 
 
 
-- Example #2
 
-- The next example takes a look at a more complex statement.
 
-- For example:
 
SELECT supplier_id
FROM suppliers
WHERE (name = 'IBM')
OR (name = 'Hewlett Packard' AND city = 'Atlantic City')
OR (name = 'Gateway' AND status = 'Active' AND city = 'Burma');
 
-- This SQL statement would return all supplier_id values where the 
-- supplier's name is IBM or the name is Hewlett Packard and the 
-- city is Atlantic City or the name is Gateway, the status is 
-- Active, and the city is Burma.
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 62 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?