Solved

multiple where clause

Posted on 2014-09-03
6
120 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Author Comment

by:pma111
ID: 40300856
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 26

Accepted Solution

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

Open in new window

0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 167 total points
ID: 40300860
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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 77

Expert Comment

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

WHERE is just once...
0
 
LVL 3

Author Comment

by:pma111
ID: 40300924
Thanks
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 166 total points
ID: 40301065
>> 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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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

695 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