Solved

multiple where clause

Posted on 2014-09-03
6
117 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
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 76

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 76

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Developer 6 48
exp/imp 25 73
form builder not starting 3 34
SQL Server: Unable to remove duplicate sets in Header/Detail 6 22
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

776 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