Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 433503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:10:50+00:00 2026-05-12T20:10:50+00:00

1st disclaimers: I’m not a programmer, never was had never been taught higher math

  • 0

1st disclaimers:

  1. I’m not a programmer, never was
  2. had never been taught “higher” math
  3. despite the upper statements sometimes I have to work with SQL.

Now I need to create a view from a select of my colleagues (who had used four unions looked like he do not know how to use or in the where part…), and now I’m here.

Is there a simple readable way of getting rid of the last UNION while getting the same result set?

Thanks in advance!

select a.prodt_cde,
      b.ccy,
      a.int_tabno,
      b.start_dn,
      b.end_dn,
      b.frte_term,
      b.base_id,
      b.ptvar,
      c.base_rate,
      c.desc_shnm,
      c.rel_day
 from linc.systwodb_ptico a, linc.systwodb_ptlfo b, linc.systwodb_baso c
 where a.prodt_cde in
      (select prodt_cde
         from linc.systwodb_ptmao
        where prodt_clas in (select prod_clas
                               from linc.systwodb_ramto
                              where main_type in (71, 72))
          and allow_dif in ('Y', 'M'))
  and a.int_type = 'LS'
  and a.int_tabno = b.int_tabno
  and b.ccy in
      (select ccy from linc.systwodb_ptmao where prodt_cde = a.prodt_cde)
  and b.base_id <> 0
  and b.base_id = c.base_id
  and b.ccy = c.ccy
  and ((b.end_dn = 0 and b.start_dn <= c.rel_day) or
      (b.end_dn <> 0 and b.start_dn <= c.rel_day and
      b.end_dn >= c.rel_day) or
      (b.start_dn > c.rel_day and not exists
       (select *
           from linc.systwodb_baso
          where base_id = b.base_id
            and ccy = b.ccy
            and rel_day = b.start_dn) and
       c.rel_day = (select NVL(max(rel_day), 0)
                       from linc.systwodb_baso
                      where base_id = b.base_id
                        and ccy = b.ccy
                        and rel_day < b.start_dn)))
-- 4. PTLFO.BASE_ID = 0, or cannot find BASO before PTLFO.START_DN 
union
select a.prodt_cde,
      b.ccy,
      a.int_tabno,
      b.start_dn,
      b.end_dn,
      b.frte_term,
      b.base_id,
      b.ptvar,
      0 as base_rate,
      ' ' as desc_shnm,
      0 as rel_day
 from linc.systwodb_ptico a, linc.systwodb_ptlfo b --, linc.systwodb_baso c
 where a.prodt_cde in
      (select prodt_cde
         from linc.systwodb_ptmao
        where prodt_clas in (select prod_clas
                               from linc.systwodb_ramto
                              where main_type in (71, 72))
          and allow_dif in ('Y', 'M'))
  and a.int_type = 'LS'
  and a.int_tabno = b.int_tabno
  and b.ccy in
      (select ccy from linc.systwodb_ptmao where prodt_cde = a.prodt_cde)
  and (b.base_id = 0 or not exists
       (select *
          from linc.systwodb_baso
         where base_id = b.base_id
           and ccy = b.ccy
           and rel_day <= b.start_dn))
;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:10:50+00:00Added an answer on May 12, 2026 at 8:10 pm

    Could you post a rough description of what this is supposed to to do? This query is very difficult to work with without knowing what it’s supposed to be doing though. The basic approach to combining these will be to use explicit joins in the from clause like so:

     from
        linc.systwodb_ptico a
        INNER JOIN linc.systwodb_ptlfo b ON a.int_tabno = b.int_tabno
        LEFT OUTER JOIN linc.systwodb_baso c ON -- some kind of horrible mess here
    

    Note the left outer join for systwodb_baso. That’s the key point for eliminating the other query. That will ensure there is a row in the result set even if there is no matching record from systwodb_baso.

    Update:

    In order to eliminate null values from the outer join, use the COALESCE function:

    select a.prodt_cde,
          b.ccy,
          a.int_tabno,
          b.start_dn,
          b.end_dn,
          b.frte_term,
          b.base_id,
          b.ptvar,
          COALESCE(c.base_rate, 0) AS base_rate,
          COALESCE(c.desc_shnm, ' ') AS desc_shnm,
          COALESCE(c.rel_day, 0) AS rel_day
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

1st the background - so that you see, that I'm not trying anything malicious:
I'm writing my 1st Java program (in Netbeans) and I'm lost. I have 2
This is my 1st C# project so I may be doing something obviously improper
i have two views 1st one is displaying list (uitableview used), user will select
I have a JTable which has 1st row blank. Now when I sort the
this is the 2nd part of the 1st question using c# pointers so pointers
I am having 2 activities: 1st Activity contains 2 arrays which are filled up
I want a shortest way to get 1st char of every word in a
I have two arrays one like 1 | 1st name 2 | 2nd name
How would I convert an NSString like 01/02/10 (meaning 1st February 2010) into an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.