Home » SQL & PL/SQL » SQL & PL/SQL » how can i Combine these 2 SQL statements into 1
how can i Combine these 2 SQL statements into 1 [message #435352] Tue, 15 December 2009 14:09 Go to next message
sjackson1972
Messages: 13
Registered: December 2009
Junior Member
Select ta.country,ta.id, sa.city, sa.state,s.zipcode
from site ta, location sa, area s
where process in 9
and s.site_seq = ta.site_seq
and sa.site_nbr=ta.site_nbr
and ta.datefile is not null
and ta.movefile is not null
and to_char(ta.datetime,'yyyy')=this_year
order by id,ta. country,s.zipcode,sa.city



Select ta.country,ta.id, sa.city, sa.state,s.zipcode
from site ta, location sa, area s
where process in 9
and s.site_seq = ta.site_seq
and sa.site_nbr=ta.site_nbr
and (ta.datefile is null or ta.autostep is null)
and to_char(ta.datetime,'yyyy')=this_year
order by id,ta. country,s.zipcode,sa.city


Re: how can i Combine these 2 SQL statements into 1 [message #435354 is a reply to message #435352] Tue, 15 December 2009 14:19 Go to previous messageGo to next message
Michel Cadot
Messages: 63806
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Depends on what you mean with "combine".
Maybe:
Select ta.country,ta.id, sa.city, sa.state,s.zipcode
from site ta, location sa, area s 
where process in 9
and s.site_seq = ta.site_seq
and sa.site_nbr=ta.site_nbr
and (( ta.datefile is not null and ta.movefile is not null)
    or (ta.datefile is null or ta.autostep is null))
and to_char(ta.datetime,'yyyy')=this_year
order by id,ta. country,s.zipcode,sa.city

Regards
Michel
Re: how can i Combine these 2 SQL statements into 1 [message #435355 is a reply to message #435354] Tue, 15 December 2009 14:25 Go to previous messageGo to next message
sjackson1972
Messages: 13
Registered: December 2009
Junior Member
just have one sql statment do the samething as the 2 seperate one..
Re: how can i Combine these 2 SQL statements into 1 [message #435357 is a reply to message #435355] Tue, 15 December 2009 14:36 Go to previous messageGo to next message
Michel Cadot
Messages: 63806
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
So "union", but it could be "intersect" or "minus".
Try what I posted.

Regards
Michel
Re: how can i Combine these 2 SQL statements into 1 [message #435425 is a reply to message #435352] Wed, 16 December 2009 04:05 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Do you want to get rows that match both of the sets of conditions, or rows that match either set of conditions?
Re: how can i Combine these 2 SQL statements into 1 [message #435434 is a reply to message #435352] Wed, 16 December 2009 04:23 Go to previous messageGo to next message
cookiemonster
Messages: 12320
Registered: September 2008
Location: Rainy Manchester
Senior Member
No rows can match both conditions, they're mutually exclusive.
Re: how can i Combine these 2 SQL statements into 1 [message #435447 is a reply to message #435434] Wed, 16 December 2009 05:03 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Quote:
No rows can match both conditions, they're mutually exclusive.


I'm not convinced. Surely a row with DATEFILE and MOVEFILE not null, and AUTOSTEP null would pass both

and ta.datefile is not null
and ta.movefile is not null
and to_char(ta.datetime,'yyyy')=this_year
order by id,ta. country,s.zipcode,sa.city

and (ta.datefile is null or ta.autostep is null)
and to_char(ta.datetime,'yyyy')=this_year
order by id,ta. country,s.zipcode,sa.city
Re: how can i Combine these 2 SQL statements into 1 [message #435468 is a reply to message #435352] Wed, 16 December 2009 06:24 Go to previous messageGo to next message
cookiemonster
Messages: 12320
Registered: September 2008
Location: Rainy Manchester
Senior Member
You're right, I missed that or.
Re: how can i Combine these 2 SQL statements into 1 [message #435501 is a reply to message #435425] Wed, 16 December 2009 08:08 Go to previous messageGo to next message
sjackson1972
Messages: 13
Registered: December 2009
Junior Member
Rows that match either of the condition
Re: how can i Combine these 2 SQL statements into 1 [message #435502 is a reply to message #435352] Wed, 16 December 2009 08:10 Go to previous messageGo to next message
cookiemonster
Messages: 12320
Registered: September 2008
Location: Rainy Manchester
Senior Member
Have you tried Michel's code?
Because as far as I can see that fulfills the requirement.
Re: how can i Combine these 2 SQL statements into 1 [message #435506 is a reply to message #435502] Wed, 16 December 2009 08:24 Go to previous message
sjackson1972
Messages: 13
Registered: December 2009
Junior Member
yes, I did. I have to revise this pl/sql package from 10 years ago and basically there's probably 5 or more sql statements like this..So, I might be on here asking for more help....

Thanks, this forum is awesome..
Previous Topic: Parallel Select
Next Topic: Creating phone number format
Goto Forum:
  


Current Time: Wed Sep 28 02:22:44 CDT 2016

Total time taken to generate the page: 0.15783 seconds