Solved

multiple where clause

Posted on 2014-09-03
6
119 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql select total by week ending 3 42
Read CLOB data from Oracle using JAVA 3 40
Sorting a SQL script 5 41
What does "Between" mean? 6 45
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

732 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