Home » SQL & PL/SQL » SQL & PL/SQL » creating view based on availability of data in 2 tables (windows, plsql)
creating view based on availability of data in 2 tables [message #628579] Wed, 26 November 2014 06:08 Go to next message
raja.i
Messages: 11
Registered: November 2014
Junior Member
Having the situation like this. Actually have to create one view and it based on following conditions
1.Two tables are there, consider t1 and t2.
2.If t1 contains the data, then i have to create the view based on datas from t1, i.e(select * from t1)
3.If no data in t1 then select * from t2.
Please guys help me to write a sql query to create the view
help me as sn as possible
Re: creating view based on availability of data in 2 tables [message #628581 is a reply to message #628579] Wed, 26 November 2014 06:11 Go to previous messageGo to next message
raja.i
Messages: 11
Registered: November 2014
Junior Member
anybody there to help me
Re: creating view based on availability of data in 2 tables [message #628584 is a reply to message #628581] Wed, 26 November 2014 06:18 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Whoa, what an impatient person! Do you really think that forum community has nothing to do but answer your questions?

Anyway: here's an idea, see what you can do with it:
select col from t1
  where not exists (select 'x' from t2)
union all
select col from t2
  where not exists (select 'x' from t1);


P.S. You didn't say what you want to do when both T1 and T2 contain data.

[Updated on: Wed, 26 November 2014 06:19]

Report message to a moderator

Re: creating view based on availability of data in 2 tables [message #628593 is a reply to message #628584] Wed, 26 November 2014 06:34 Go to previous messageGo to next message
raja.i
Messages: 11
Registered: November 2014
Junior Member
thanks much
Re: creating view based on availability of data in 2 tables [message #628613 is a reply to message #628593] Wed, 26 November 2014 07:51 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
raja.i wrote on Wed, 26 November 2014 18:04
thanks much

First you were impatient to get an answer. When LF provided a solution, don't you think you should feedback whether the solution worked for you. And, there is also something he asked you, what about you answering now?

P.S. What if both tables don't have any rows?

[Updated on: Wed, 26 November 2014 07:55]

Report message to a moderator

Re: creating view based on availability of data in 2 tables [message #628615 is a reply to message #628613] Wed, 26 November 2014 07:57 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Well, that's quite obvious. You can't have something out of nothing.
Re: creating view based on availability of data in 2 tables [message #628617 is a reply to message #628613] Wed, 26 November 2014 07:58 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Lalit Kumar B wrote on Wed, 26 November 2014 13:51
raja.i wrote on Wed, 26 November 2014 18:04
thanks much

P.S. What if both tables don't have any rows?

Why are we considering any possibility other than no rows for that case?
Re: creating view based on availability of data in 2 tables [message #628620 is a reply to message #628617] Wed, 26 November 2014 08:08 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
I don't know. I am expecting an answer from OP.

We don't know why T1 would have no rows, and how would T2's data suffice. It means, T1 and T2 has similar data. So, OP needs to tell us about all such cases.
Re: creating view based on availability of data in 2 tables [message #628621 is a reply to message #628620] Wed, 26 November 2014 08:12 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Unless there is also a t3 the nature of the relationship of t1 and t2 isn't going to change the result if both are empty.
Re: creating view based on availability of data in 2 tables [message #628622 is a reply to message #628621] Wed, 26 November 2014 08:15 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Agreed. Many possibilities, and OP needs to clarify. Just curious to see the impatient asker to get back Smile
Re: creating view based on availability of data in 2 tables [message #628649 is a reply to message #628622] Wed, 26 November 2014 13:59 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
WHAT HAPPENS IF BOTH t1 and t2 contain data. Do you want to see all the data in both tables or no data
Re: creating view based on availability of data in 2 tables [message #628668 is a reply to message #628649] Wed, 26 November 2014 21:35 Go to previous messageGo to next message
Kevin Meade
Messages: 2103
Registered: December 1999
Location: Connecticut USA
Senior Member
Quote:
Well, that's quite obvious. You can't have something out of nothing.


Actually LittleFoot, this is the latest theory of physics: the universe was indeed created from nothing. Have you not heard. The idea as I understand it with my miniscule mind is that 0 begat -1 and 1 which together add up to 0. Thus as long as all matter in the universe is balanced out by an equal amount of "opposite matter" (whatever name they are giving it these days), then the theory says that indeed everything adds up to nothing and thus if -1 plus +1 = 0 then it should be possible for 0 to give rise to -1 and +1, or in the case of our universe, -(a crap-load of matter) and +(a crap-load of matter), and therefore we can have the universe because a balanced universe is just one of an infinite number of possible manifestations of nothing.

Thought I'd point it out. Kevin
Re: creating view based on availability of data in 2 tables [message #628678 is a reply to message #628668] Thu, 27 November 2014 00:20 Go to previous message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Thank you, Kevin! I didn't hear that. Yes, I do read National Geographic, but I'm still on September (have to keep up!) and didn't read nor hear anything about that theory yet.

Could you give me your dealer's number, I'd like to have a bit of whatever you are taking /forum/fa/917/0/
Previous Topic: OUTPUT Of SYS_REFCURSOR
Next Topic: number to character conversion
Goto Forum:
  


Current Time: Thu Apr 18 03:04:56 CDT 2024