Solved

multiple where clause

Posted on 2014-09-03
6
118 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 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
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!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax issue with my Where Clause SQL 2012 20 38
SQL Rewrite without the NULLIF 4 25
Excess Redo 3 32
Return Rows as per Quantity of Columns Value In SQL 6 27
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…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

749 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