Home » SQL & PL/SQL » SQL & PL/SQL » Display results in one query with different WHERE conditions
Display results in one query with different WHERE conditions [message #223567] Fri, 09 March 2007 10:06 Go to next message
poratips
Messages: 345
Registered: April 2005
Location: IL
Senior Member
Hi,

I need to display result sets based on my where condition but wants to handle in one query, how can I do?

I have table called MAP

CREATE TABLE MAP (

ID                               VARCHAR2(10) PRIMARY KEY,

CATEGORY                   VARCHAR2(20),

TYPE                          VARCHAR2(10),

NAME                          VARCHAR2(50)

create_date                 DATE,

update_date                DATE,

create_by                  DATE

MAP_DESC                 VARCHAR2(100)

)

Now I want to write query as below -

If CATEGORY = &val then display resultsets based on this val varibles

if TYPE = &val then display resultsets based on this val varibles

if name = &val then display resultsets based on this val varibles

I would like to write the query for all three conditions in a one but this condition will be either one matching or two condition matching or all three matching or none matching but resultsets should be depends on which matching.

select * from MAP where CATEGORY = VARiable

select * from MAP where TYPE = VARiable

select * from MAP where NAME = VARiable

So it will either where CATEGORY = VARiable and TYPE = VARiable

OR/AND it will either where CATEGORY = VARiable and NAME = VARiable

OR/AND it will either where TYPE = VARiable and NAME = VARiable

OR NONE is matching

Thanks


Re: Display results in one query with different WHERE conditions [message #223577 is a reply to message #223567] Fri, 09 March 2007 11:53 Go to previous messageGo to next message
gintsp
Messages: 118
Registered: February 2007
Senior Member
Is this http://asktom.oracle.com/pls/asktom/f?p=100:11:2120883106158::::P11_QUESTION_ID:1288401763279 what are you looking for?

Gints Plivna
http://www.gplivna.eu
Re: Display results in one query with different WHERE conditions [message #228572 is a reply to message #223577] Tue, 03 April 2007 07:12 Go to previous message
gokanidisha
Messages: 2
Registered: March 2007
Location: pune
Junior Member

hi
u can use case in this the syntax is as below


CASE expression
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
...
WHEN condition_n THEN result_n
ELSE result END

regards,
Disha
Previous Topic: SP2-0310
Next Topic: to get the round off value of a float value
Goto Forum:
  


Current Time: Sun Dec 11 04:10:06 CST 2016

Total time taken to generate the page: 0.11866 seconds