If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Multiple view from a single select statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-03, 03:42
amit_parmar amit_parmar is offline
Registered User
 
Join Date: Dec 2003
Posts: 5
Multiple view from a single select statement

Hi,
I want to write an SQL query which should return me 2 kinds of outputs depending on which condition is true. i.e.

the query should be something like

select someview if (condition1 = true)
else select someotherview if (condition2 = true)

where someview is a set of columns from one table only, and someotherview is a set of columns which is a superset of someview (& is generated from two tables, which have no common field)

Let me explain this further --
I want to select data from one table and a single field from other table, however if I the first table does not return any data, I still want data from the other table to be returned.
Can I write a SQL query to do this?

-- Amit
Reply With Quote
  #2 (permalink)  
Old 12-16-03, 04:09
edwinjames edwinjames is offline
Registered User
 
Join Date: Dec 2003
Posts: 74
do a union query.

select * from table1
union
select 'ed' from table2;

if table 1 is return not rows table2 will still return data.

Does this answer your question?
Reply With Quote
  #3 (permalink)  
Old 12-16-03, 04:14
amit_parmar amit_parmar is offline
Registered User
 
Join Date: Dec 2003
Posts: 5
Quote:
Originally posted by edwinjames
do a union query.

select * from table1
union
select 'ed' from table2;

if table 1 is return not rows table2 will still return data.

Does this answer your question?

I know, that I can use a union, however I want to support TimesTen & Oracle using thsame query...TT does not allow union while oracle does, can I write another query which emulates union?
Reply With Quote
  #4 (permalink)  
Old 12-16-03, 05:24
edwinjames edwinjames is offline
Registered User
 
Join Date: Dec 2003
Posts: 74
I am sorry I am not farmiliar with TT.

Does it support outer joins?
Reply With Quote
  #5 (permalink)  
Old 12-16-03, 05:39
amit_parmar amit_parmar is offline
Registered User
 
Join Date: Dec 2003
Posts: 5
Quote:
Originally posted by edwinjames
I am sorry I am not farmiliar with TT.

Does it support outer joins?

Yes it dows, hence I am now using outer joins
Reply With Quote
  #6 (permalink)  
Old 12-16-03, 09:53
edwinjames edwinjames is offline
Registered User
 
Join Date: Dec 2003
Posts: 74
Talking

Glad to be of help

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On