Solved

multiple where clause

Posted on 2014-09-03
6
115 Views
Last Modified: 2014-09-22
Excuse the basic level of the question, but I have a large SQL query with multiple where clauses, one of which is where I need to filter for:

select * from mytable
where field1= 'value1' OR 'value2' OR 'value3' OR 'value4'

Is there anyway to do the where clause for where the field1 contains multiple options, the way I thought of doing it above doesnt work. Can you do this in a single where clause, or do you need a where clause per possible value. Just somewhat concerned that OR could ignore all the initial logic and treat that as an option for the data in itself.
0
Comment
Question by:pma111
6 Comments
 
LVL 3

Author Comment

by:pma111
Comment Utility
select * from mytable
where myfield= 'abc' OR
where myfield= 'def' OR
where myfield= 'ghi' OR
where myfield= 'jkl'

The above doesnt work either, produces the error ORA-00936: missing expression
0
 
LVL 25

Accepted Solution

by:
Shaun Kline earned 167 total points
Comment Utility
You can use an IN clause:
where field1 IN ('value1','value2','value3','value4')

Open in new window

0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 167 total points
Comment Utility
Use IN:
where field1 in ( 'value1','value2','value3' ,'value4')

Otherwise just repeat field1=:
where field1= 'value1' OR field1= 'value2' OR field1='value3' OR field1= 'value4'
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>> The above doesnt work either, produces the error ORA-00936: missing expression

WHERE is just once...
0
 
LVL 3

Author Comment

by:pma111
Comment Utility
Thanks
0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 166 total points
Comment Utility
>> Can you do this in a single where clause<<
You can only have a single where clause, although that clause can contain many filters using combinations of AND and OR. Just be careful when combining ANDs and ORs -
select ...
where condition1 or condition2 and condition3 returns records where condition1 exists or both condition2 and condition3 exist
select ...
where (condition1 or condition2) and condition3 returns records where condition1 or condition2 exists and condition3 exists
No points please, just trying to provide some understanding.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to recover a database from a user managed backup

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now