Joining these these two queries (one regular and one grouped)

Hello
I have these two queries I would like to join, however the later is a grouped query how can I join it with the first query?
Has to be joined on EventId. The second query is a total table scan.
SELECT AH.EventID,
AH.TechnicalAddress, AH.AlarmAlias, AH.AlarmPath as [OrgAlarmPath], AH.AlarmCounter as AlarmCount, AH.EventDateTime as EventTime,
AH.[Priority], AH.AlarmMessage, AH.EventText, AH.CallListName, AH.AlarmReadDate as EndTime,
AH.alh_EventEndedUserRemark as [EndRemark] --, SUM(seconds) here, and AlarmSessions here
FROM AlarmHistory AH
WHERE (AH.HeartbeatAlarm = 0 OR AH.HeartbeatAlarm IS NULL) AND
((AH.CallListID IS NOT NULL) OR (AH.alh_IsForStatistics = 1)) AND
(NOT (AH.alh_t_EventSubCode is NULL or AH.AlarmReadByUserID is NULL))
ORDER BY AH.EventID DESC
SELECT ia.eventID, SUM(DATEDIFF(SECOND,ia.eventTime,r.eventTime)) AS seconds, COUNT(*) as AlarmSessions
FROM alarmHistoryLog ia
INNER JOIN alarmHistoryLog r
ON ia.EventId = r.EventId
AND r.EventTypeId = 2
AND r.EventSeq = (SELECT MIN(eventSeq) FROM alarmHistoryLog WHERE eventSeq > ia.EventSeq AND EventTypeId = 2)
WHERE ia.EventTypeId = 0
group by ia.EventId
order by EventId desc
Henry

Try the below:
;with ctefirst as
SELECT AH.EventID,
AH.TechnicalAddress, AH.AlarmAlias, AH.AlarmPath as [OrgAlarmPath], AH.AlarmCounter as AlarmCount, AH.EventDateTime as EventTime,
AH.[Priority], AH.AlarmMessage, AH.EventText, AH.CallListName, AH.AlarmReadDate as EndTime,
AH.alh_EventEndedUserRemark as [EndRemark] --, SUM(seconds) here, and AlarmSessions here
FROM AlarmHistory AH
WHERE (AH.HeartbeatAlarm = 0 OR AH.HeartbeatAlarm IS NULL) AND
((AH.CallListID IS NOT NULL) OR (AH.alh_IsForStatistics = 1)) AND
(NOT (AH.alh_t_EventSubCode is NULL or AH.AlarmReadByUserID is NULL))
), ctesecond as
SELECT ia.eventID, SUM(DATEDIFF(SECOND,ia.eventTime,r.eventTime)) AS seconds, COUNT(*) as AlarmSessions
FROM alarmHistoryLog ia
INNER JOIN alarmHistoryLog r
ON ia.EventId = r.EventId
AND r.EventTypeId = 2
AND r.EventSeq = (SELECT MIN(eventSeq)
FROM alarmHistoryLog WHERE eventSeq > ia.EventSeq AND EventTypeId = 2)
WHERE ia.EventTypeId = 0
group by ia.EventId
Select A.*,B.seconds,B.AlarmSessions From ctefirst A
Inner join ctesecond B On A.EventId = B.EventID
Please mark this reply as answer if it solved your issue or vote as helpful if it helped.
 [Blog]

Similar Messages

  • Joining these two queries

    I have two queries. The First one is long but very simple. All it has is long list of columns.
    First one:
    SELECT CL.CLIENT_ID, CA.CASE_ID, to_char(SYSDATE,'RRMMDD'),
    CL.MASTER_CLIENT_ID,
    CL.NAME1,
    nvl(CL.NAME2,' '),
    nvl(CL.ADDRESS1,' '),
    nvl(CL.ADDRESS2,' '),
    CL.POCO_POSTAL_CODE, nvl(CL.CITY,' '),
    nvl(CL.AUTO_SURV_CODE,0),
    CA.Col_Collector_Id
    FROM CLIENT CL, CASES CA
    WHERE CA.CL_CLIENT_ID = CL.CLIENT_ID AND
    CA.CASE_ID = :current_case_id
    Second one:
    SQL SELECT nvl(REF_NO,' '), nvl(to_char(DATE_OF_JUDGEMENT,'rrmmdd'),' ')
    FROM CASE_INSTANCES
    WHERE IN_INSTANCE_TYPE IN (1,8) AND
    CA_CASE_ID = :current_case_id AND
    PETITION_DATE = (SELECT max(PETITION_DATE)
    FROM CASE_INSTANCES
    WHERE IN_INSTANCE_TYPE IN (1,8)
    AND CA_CASE_ID = :current_case_id
    AND ROWNUM < 2 );
    The :current_case_id is passed as a parameter. The table in the second query i.e. CASE_INSTANCES is related to the first query with the CA_CASE_ID. Not all records fetched by the first query have a record in the second query. So you might have to use a LEFT JOIN or something. trying to join these two has worn me out. Please help me out someone.

    Hi,
    Simplified Solution:
    SELECT * FROM (
                        SELECT CL.CLIENT_ID, CA.CASE_ID, TO_CHAR(SYSDATE,'RRMMDD'),
                        CL.MASTER_CLIENT_ID,
                        CL.NAME1,
                        NVL(CL.NAME2,' '),
                        NVL(CL.ADDRESS1,' '),
                        NVL(CL.ADDRESS2,' '),
                        CL.POCO_POSTAL_CODE, NVL(CL.CITY,' '),
                        NVL(CL.AUTO_SURV_CODE,0),
                        CA.Col_Collector_Id
                        FROM CLIENT CL, CASES CA
                        WHERE CA.CL_CLIENT_ID = CL.CLIENT_ID ) a,
                        (SELECT NVL(REF_NO,' '), NVL(TO_CHAR(DATE_OF_JUDGEMENT,'rrmmdd'),' '),CA_CASE_ID
                             FROM CASE_INSTANCES
                             WHERE IN_INSTANCE_TYPE IN (1,8) AND
                             CA_CASE_ID = :current_case_id AND
                             PETITION_DATE = (SELECT MAX(PETITION_DATE)
                                                      FROM CASE_INSTANCES
                                                      WHERE IN_INSTANCE_TYPE IN (1,8)
                                                      AND CA_CASE_ID = :current_case_id
                                                      AND ROWNUM < 2
                        ) b
    WHERE a.case_id = b.ca_case_id(+)
    Regards
    K.Rajkumar

  • How to join these two queries

    Hi experts,
    I need to join two queries but not sure how:
    select id from test_table1;
    select *
      from table(f_function(null
                           ,null
                           ,1 -- the id
                           ,sysdate);One query has IDs needed to run the second query. Is there a way to join those two?
    The result should be all columns from test_table1 + all columns from f_function.
    Best regards,
    Igor
    Edited by: Igor S. on Mar 8, 2013 5:18 AM

    Hi,
    Igor S. wrote:
    select  *
    from  test_table1,
    table(
    f_function(
    null,
    null,
    id,
    sysdate
    select  *
    from  test_table1,
    table(
    f_function(
    null,
    null,
    id,
    sysdate
    ) xyz
    where test_table1.id = xyz.id
    /So these two queries are the same?Try it and see.
    You'll find that the 2nd one produces an error. But if you change it to
    select  *
      from  test_table1,
            table(
                  f_function(
                             null,
                             null,
                             id,
                             sysdate
                            )      -- No alias here
                 ) xyz             -- Alias here, instead
    where test_table1.id = xyz.id
    /Then, assuming f_function produces a column called id, it will work.
    Whether it produces the same results or not depends on what the function returns, and whether either id is NULL.
    If the id column that the function returns is the same as the id value that you pass to it, and is never NULL, then the 2 queries will produce the same results.
    Either way, each row of test_table1 will be joined to each row that the function produces with the argument(s) from that row. The column names produced by the function and the values in those columns are determined by the function; they do not need to have anything in common with any table. In practice, a function like f_function will usually not return an column that is always identical to any of its inputs, since that value is already available from the input.

  • Can anyone join these two into one?

    <?if:1=1?>Page 1<?end if?><?if:1!=1?>Other Page<?end if?>
    <?fo:page-number?>
    I want to replace the first 1 with the page number function...
    Please help me, I'n running out of time.

    Hi Tim,
    I don't think it is important which functionallity I want to achieve. My real question is: can I use a function (like <?fo:page-number?> in a function (like <?if:?>).
    Kind regards,
    Corné

  • Whats the difference between these two queries ? - for tuning purpose

    Whats the difference between these two queries ?
    I have huge amount of data for each table. its takeing such a long time (>5-6hrs).
    here whice one is fast / do we have any other option there apart from listed here....
    QUERY 1: 
      SELECT  --<< USING INDEX >>
          field1, field2, field3, sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end)
        FROM
          tab1 inner join tab2 on condition1 inner join tab3 on condition2 inner join tab4 on conditon3
        WHERE
         condition4..10 and
        GROUP BY
          field1, field2,field3
        HAVING
          sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end) <> 0;
    QUERY 2:
       SELECT  --<< USING INDEX >>
          field1, field2, field3, sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0))
        FROM
          tab1, tab2, tab3, tab4
        WHERE
         condition1 and
         condition2 and
         condition3 and
         condition4..10
        GROUP BY
          field1, field2,field3
        HAVING
          sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0)) <> 0;
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    My feeling here is that simply changing join syntax and case vs decode issues is not going to give any significant improvement in performance, and as Tubby points out, there is not a lot to go on. I think you are going to have to investigate things along the line of parallel query and index vs full table scans as well any number of performance tuning methods before you will see any significant gains. I would start with the Performance Manual as a start and then follow that up with the hard yards of query plans and stats.
    Alternatively, you could just set the gofast parameter to TRUE and everything will be all right.
    Andre

  • What is the difference between these two reports MC.1 and MB5L

    Hi
    what is the difference between these two reports MC.1 and MB5L?
    what is the Purpose of each report?
    Material ledger is activated for this plant, we found some amount difference between these two reports, my client accounting department used to compare these two reports while year end/month end closing
    Thanks
    Raju

    MC.1 will give you the report for plant analysis as per plant .
    MB5L report will give you list of stock value as per G/L account wise.

  • The box {cannot use app in safe mode} would you like to temporarily switch, I press continue and it goes to please log in, and these two boxs go back and forth not allowing me to continue the game like farmville etc.

    the dialogue box says {we cannot continue with this app in a secure mode. Would you like to temporarily disable to an unsecured mode and you will be able to use the app at your next log in.} I push the "Continue" button, not the cancel button and it tells me to {Please log in, you are not logged in}. I will then log in and the original window as mentioned above comes back again. These two boxes go back and forth when I try to continue in any of the games on Facebook.

    Hi thanks for all the concern and replies. I've tried all that.
    I had just got it back from the shop last Friday. It was there for around two weeks. It was a faulty GPU (when you see garbled display that's consisten when booting it the GPU). I have a strong feeling it's related to the Lion install 10.7 or 10.7.1 and may be similar to reports of Mac laptops overheating. It's good the GPU is removable, it might have taken 3 week or a month if it had been the whole board.
    It's a blessing in disguise though as with all or most cases because I also got to have the LCD replaced for excessive backlight bleeding (in my opinion), the dead pixel from the previous LCD isn't there anymore (though under the glass there're some smudges but nothing crucial). The backlight bleeding is still the same though in my opinion but at least it's new.
    It's a great thing I bought Applecare. I didn't buy it for the iPhone because that's more durable (my iPhone 3G's 3 years old now and it's still solid. Although there are scratches and a crack at the back at the bottom, got sqeezed under the table I think when I sat). I think Applecare is a good recommend for things that get hot like desktop and laptop Macs(are the iOS considered Macs btw?) which are twice or thrice the price of iOS devices.
    Gbu.

  • I need opinions. I currently on dilemma on buying iPod Touch 4 or Samsung Galaxy Tab. Comparing these two, which one is better? Why? Tq.

    Well, I want to buy a new gadget for myself. But I currently don't know which one to choose yet. Both iPod Touch 4 and Samsung Galaxy Tab are great inventions! But i can't afford to buy both of them. So i'm asking all of you, any ideas or opinions on these two gadget? Which one is better and why? What do iPod 4 have that Samsung Tab don't have and vice versa. Thank you so much if you replying this.

    I'm having the same issues you are having on my S3.  I was on the phone with tech support (Verizon) last Friday for about an hour.  I had to get a bit nasty with the tech when he attempted to blame Samsung for this (Samsung didn't release that update without Verizon's OK- and have you noticed Verizon has added their logo to the startup now?).
    My data usage has gone up, battery draining much faster (and I have an extended battery!) and I had to re-load some of my widgets on the phone (including the My Verizon widget).  The tech had me start the phone in Safe Mode (holding down the power, volume rocker and Home button at the same time until the Samsung logon screen shows then let go of the power button while continuing to hold the other two buttons until the phone logs on completely).
    Whatever he did remotely seemed to make the phone act better yet he decided I need the update 'reflashed' to the phone.  First he credited my account $30 to take care of any possible data overages.  He then contacted my local Best Buy store to see if they could 'reflash' (upload the update again) the phone. 
    I went to Best Buy and had it done the next day.  I think the phone was better before the 'reflash'!  The tech gave me his personal Verizon cell number so I will be calling him back today.
    An update for the update is coming yet the release date hasn't been confirmed.  The tech said my account will be monitored for any overages in which I will received credits to cover it.
    Good luck, Ginger- and I agree with you: if this doesn't get fixed I will move my business to T-Mobile!

  • These two queries return same data?

    select * from voucher where (unit = 'TIA4M' or unit = 'TIAFM' or unit = 'TIAWM' or unit = 'TIATW' or unit = 'TIAPA' )
    and invoice_dt >= TO_DATE('01/01/2006', 'MM/DD/YYYY')
    select * from voucher where unit in ('TIA4M', 'TIAFM', 'TIAWM', 'TIATW', 'TIAPA')
    and invoice_dt >= TO_DATE('01/01/2007', 'MM/DD/YYYY')
    Also the first is much faster right?

    The first query is using a date of Jan 1, 2006. The second query is using a date of Jan 1, 2007.
    Assuming that is a typo, the two queries are semantically identical. Since Oracle can easily transform an IN-list to a series of OR's, though, I would doubt that there would be any performance difference between them absent the 2006/2007 change.
    Justin

  • Two Queries, One View Object

    I have two fairly different ways to query the same table.
    One is a Spatial query, which returns rows that are within a radius of a starting point. This has the distance from the starting point as one of the expressions in the select list. You cannot have this expression in the select list unless the WHERE clause includes the spatial condition.
    The other way to query the table is with more "normal" WHERE clauses, like "WHERE name LIKE '%'||:nameParm||'%'", probably created as ViewCriteria. Distance is meaningless for this sort of query.
    Version one of the application solved this by having a single VO, and methods that reset the query as needed. But this had passivation/activation problems - when activated, the query would reset to the original query, but there might be bind variables left over from the other query. Solved it by not changing the query until just before it was executed. I'm not happy with this solution - it seems fragile to me.
    I could have two View Objects each with one of the queries. I envision a user interface where the user can choose which way to query the table, and some logic would have to decide which bind variables to obtain and which VO to execute. But I'd like the results from either to appear in the same ADF Faces table component. The rest of the select list is the same and would have all the same labels, etc. in the UI. I don't mind if the VO for which Distance is meaningless has a Distance attribute that is always null - I would simply set that column to not display if not appropriate.
    Possibilities: Subclass the two VOs from a third VO with a very basic version of the query, and use the parent VO in the ADF Faces table component? Or can I make the value attribute of the table dynamic - select the right VO at run time?

    Okay... no answer to this one, so I kept working on my own answer.
    Here's what I did:
    I created a VO with a very basic query that has all WHERE criteria that are common to all queries. That includes three bind variables. Call this one "BaseVO".
    I used TO_NUMBER(NULL) for the distance column that is only meaningful when you are doing a Spatial query.
    I created all of my View Links to this VO. I also did all of my UI defaults against this VO.
    Then I created two VO's that extend BaseVO. Each has the same attributes as the original, but one (call it NonSpatialVO) has View Criteria that encapsulate the non-spatial ways to query the table.
    The other VO, SpatialVO, has a different query, but it has the same select list, so it still maps to the same attributes. It has a where clause for searching by latitude and longitude, so these are bind variables. And the spatial function for the distance from the starting point replaces TO_NUMBER(NULL) in the query.
    So far, so good - the UI and View Links apply to NonSpatialVO and SpatialVO, even though they were only defined in BaseVO. It all works as expected when I run the Application Module.
    Next step - on to using the VOs in some pages in the ViewController project.
    It's going to have to decide dynamically which VO needs to be instantiated and executed, and then display the results in a table - the same table no matter which VO was used. I imagine that I'll use BaseVO to drag and drop the table on the page, but use EL to associated the correct VO with the "value" property.
    If anyone has done something like this before - your comments and advice are welcome.

  • Outer join: difference between two queries

    Below two queries that should give the same results in my opinion. I want all the records from u_protocol and only the value of pval.u_protocol_variable_value if present.
    Why does the outer join in query2 doesn't work like in query1?
    Query1:
    select p.u_protocol_id, i.u_protocol_variable_value
    from lims_sys.u_protocol p,
       select pval.u_protocol_id, pval.u_protocol_variable_value
       from lims_sys.u_protocol_variable pvar, lims_sys.u_protocol_value_user pval
       where pvar.u_protocol_variable_id = pval.u_protocol_variable_id
       and pvar.name = 'VALUE_Protocol_Group'
    ) i  
    where p.u_protocol_id  = i.u_protocol_id (+)
    Query2:
    select prt.u_protocol_id, pval.u_protocol_variable_value
    from lims_sys.u_protocol prt, lims_sys.u_protocol_variable pvar, lims_sys.u_protocol_value_user pval
    where pvar.u_protocol_variable_id = pval.u_protocol_variable_id
    and prt.u_protocol_id = pval.u_protocol_id (+)
    and pvar.name = 'VALUE_Protocol_Group'

    In the first query restriction pvar.name = 'VALUE_Protocol_Group' is limited to your inline view. So when you do a outer join with the u_protocol table you will get the number of records which are there in the u_protocol table.
    But when you gave the restriction pvar.name = 'VALUE_Protocol_Group' outside the inline view, the restriction was based on the resultset as a whole. So you will get only those records which have pvar.name = 'VALUE_Protocol_Group' condition satisfied.
    Hope the following illustration helps:
    SQL> CREATE TABLE TEST_TAB
      2  AS
      3  SELECT level col_1, chr(65+level-1) col_2 FROM Dual
      4  CONNECT BY LEVEL <= 10
      5  /
    Table created.
    SQL> SELECT * FROM TEST_TAB
      2  /
         COL_1 COL_
             1 A
             2 B
             3 C
             4 D
             5 E
             6 F
             7 G
             8 H
             9 I
            10 J
    10 rows selected.
    SQL> CREATE TABLE TEST_TAB_B
      2  AS
      3  SELECT level col_3, chr(65+level-1) col_4 FROM Dual
      4  WHERE Level NOT IN (2,3,4)
      5  CONNECT BY LEVEL <= 10
      6  /
    Table created.
    SQL> SELECT * FROM TEST_TAB_B
      2  /
         COL_3 COL_
             1 A
             5 E
             6 F
             7 G
             8 H
             9 I
            10 J
    7 rows selected.
    SQL> SELECT a1.col_1, a1.col_2, a2.col_3, a2.col_4 FROM TEST_TAB a1,
      2  TEST_TAB_B a2
      3  where a1.col_1 = a2.col_3(+)
      4  order by a1.col_1
      5  /
         COL_1 COL_      COL_3 COL_
             1 A             1 A
             2 B
             3 C
             4 D
             5 E             5 E
             6 F             6 F
             7 G             7 G
             8 H             8 H
             9 I             9 I
            10 J            10 J
    10 rows selected.Notice the output without any extra conditions: You will get all the values from TEST_TAB and matching records from TEST_TAB_B. Non-matching records are outputed as NULL.
    Following Query is resemblence to your first query
    SQL> SELECT a1.col_1, a1.col_2, a2.col_3, a2.col_4 FROM TEST_TAB a1,
      2  (SELECT * FROM TEST_TAB_B where col_4='A') a2
      3  where a1.col_1 = a2.col_3(+)
      4  order by a1.col_1
      5  /
         COL_1 COL_      COL_3 COL_
             1 A             1 A
             2 B
             3 C
             4 D
             5 E
             6 F
             7 G
             8 H
             9 I
            10 J
    10 rows selected.Here TEST_TAB_B Table is restricted with a condition which will restrict the inline view to have only one record. So when you outer join the inline view you will get output as shown above.
    The following query resembles to your second query.
    SQL> SELECT a1.col_1, a1.col_2, a2.col_3, a2.col_4 FROM TEST_TAB a1,
      2  TEST_TAB_B a2
      3  where a1.col_1 = a2.col_3(+)
      4  and a2.col_4 = 'A'
      5  order by a1.col_1
      6  /
         COL_1 COL_      COL_3 COL_
             1 A             1 A
    1 row selected.
    SQL> DROP TABLE TEST_TAB_B
      2  /
    Table dropped.
    SQL> DROP TABLE TEST_TAB
      2  /
    Table dropped.
    SQL> To understand this lets break up the resultset.
    Resultset brought by join condition would be something like :
        COL_1 COL_      COL_3 COL_
             1 A             1 A
             2 B
             3 C
             4 D
             5 E             5 E
             6 F             6 F
             7 G             7 G
             8 H             8 H
             9 I             9 I
            10 J            10 JAgreed?
    Now when you add the extra condition a2.col_4 = 'A' thecondition will act upon the above resultset there by restricting the records to:
         COL_1 COL_      COL_3 COL_
             1 A             1 AHope this helps.
    Regards,
    Jo

  • How do I join together these two queries?

    Hi I have these queries:
    select br_no, br_managersname from BRANCH order by br_managersname;
    select sum(rent_endkms-rent_startkms) as "TOTAL KMS TRAVELLED" from RENTAL group by BR_NO having SUM(rent_endkms-rent_startkms) = (select MAX(sum(rent_endkms-rent_startkms)) from RENTAL group by BR_NO);
    They each output their own tables, but I wanna join them together so they output as one table. Unfortunately, I really suck at joining tables. Can anyone help?

    Hmm... Not enought information again... Any way, let me consider br_no as the key between the two query. In that case i came up with this.
    with query1
    as
    select br_no, br_managersname
    from BRANCH order by br_managersname
    query2
    as
    select br_no, sum(rent_endkms-rent_startkms) as total_kms_travelled
      from RENTAL
    group by BR_NO
    having SUM(rent_endkms-rent_startkms) = (select MAX(sum(rent_endkms-rent_startkms))
                                               from RENTAL
                                              group by BR_NO)
    select q1.bar_no, q1.br_managersname, q2.total_kms_travelled
      from query1 q1
      join query2 q2
        on q1.br_no = q2.br_no

  • Can these two queries be combined

    Is there a more eloquent way of joining the two tales to only
    get those records that have more than one record. Instead of
    writing two seperated queries, can one query achieve the
    results?

    Could this also have been solved with one query by just doing
    the following?
    <cfquery name="get_mult_posn" datasource="#dsn#">
    SELECT a.posn_id, a.pers_id, a.job_titl, frst_name,
    mid_name, last_name
    FROM posntable a, perstable b
    WHERE a.pers_id = b.pers_id
    </cfquery>

  • Help me join these two scripts please!

    hello, I have two statements
          SELECT
       --distinct
             a.address_line3
            ,a.address_line4
            ,a.address_line5
            ,a.post_code
            ,a.tel_no
            ,l.claim_no
            ,lpad(row_number() OVER(ORDER BY l.claim_no), 6, '0') AS snum
            ,l.input_title
            ,l.input_surname
         ,l.INPUT_HOUSE_NO
         ,l.INPUT_BUILDING
         ,l.INPUT_FLAT
            ,l.input_address_line1
            ,l.input_address_line2
            ,l.input_address_line3
            ,l.input_address_line4
            ,l.input_post_code     
            ,to_char(sysdate, 'MON YYYY') AS prntdate
         ,l.input_title AS input_title2
         ,l.input_surname AS input_surname2
         ,h.lpa_amt
         ,h.START_DATE
         ,h.elig_rate
         ,h.rate_rebate
         ,h.rr_amt
         ,h.lpa_applic
         ,h.lpa_amt AS lpa_amt2
         ,a.sho_name
            FROM lpa_input l, lpa_address a, lpa_history h, lpa_credhist_ha c
         wHERE a.aun_code = l.input_aun_code
         AND l.claim_no = h.claim_no
         AND h.claim_no = c.claim_no
         and ent_seqno = (select max (ent_seqno) from lpa_history where claim_no = l.claim_no)
    SELECT DISTINCT CLAIM_NO FROM LPA_HISTORY
    WHERE DATE_created > '01/APR/2009' AND CLAIM_NO NOT IN
    (select CLAIM_NO from lpa_notifications)
    ORDER BY CLAIM_NOCan i put this select statment at the end of the first script??
    Thanks

    Hi try this
    SELECT
    distinct
    a.address_line3
    ,a.address_line4
    ,a.address_line5
    ,a.post_code
    ,a.tel_no
    ,l.claim_no
    ,lpad(row_number() OVER(ORDER BY l.claim_no), 6, '0') AS snum
    ,l.input_title
    ,l.input_surname
    ,l.INPUT_HOUSE_NO
    ,l.INPUT_BUILDING
    ,l.INPUT_FLAT
    ,l.input_address_line1
    ,l.input_address_line2
    ,l.input_address_line3
    ,l.input_address_line4
    ,l.input_post_code
    ,to_char(sysdate, 'MON YYYY') AS prntdate
    ,l.input_title AS input_title2
    ,l.input_surname AS input_surname2
    ,h.lpa_amt
    ,h.START_DATE
    ,h.elig_rate
    ,h.rate_rebate
    ,h.rr_amt
    ,h.lpa_applic
    ,h.lpa_amt AS lpa_amt2
    ,h.CLAIM_NO
    ,a.sho_name
    FROM lpa_input l, lpa_address a, lpa_history h, lpa_credhist_ha c
    WHERE a.aun_code = l.input_aun_code
    AND l.claim_no = h.claim_no
    AND h.claim_no = c.claim_no
    AND ent_seqno = (select max (ent_seqno) from lpa_history where claim_no = l.claim_no)
    AND DATE_created > '01/APR/2009' AND CLAIM_NO NOT IN
    (select CLAIM_NO from lpa_notifications)
    ORDER BY h.CLAIM_NONOTE: not tested.

  • I have these below queries. How do I join these 3 queries into a single query?

    1st query:
    SELECT TOP(1) @tmpOnlineCat = ac.AlertCatID
    FROM alert.AlertCategory ac
    WHERE ac.FkAlertID = 2
    AND ac.FkAlertTypeID = 3
    2nd query
    SELECT TOP(1) @tmpOfflineCat = ac.AlertCatID
    FROM alert.AlertCategory ac
    WHERE ac.FkAlertID = 3
    AND ac.FkAlertTypeID = 3
    3rd query
    INSERT INTO item.ItemOnlineOfflineAlertCategory
    VALUES
    @tmpPkItemID,
    @tmpOfflineCat,
    @tmpOnlineCat
    mayooran99

    I think this is all what you need!
    INSERT INTO item.ItemOnlineOfflineAlertCategory
    SELECT @tmpPkItemID,
    MAX(CASE WHEN FkAlertID = 2 THEN AlertCatID END) AS tmpOnlineCat,
    MAX(CASE WHEN FkAlertID = 3 THEN AlertCatID END) AS tmpOfflineCat
    FROM alert.AlertCategory
    WHERE FkAlertTypeID = 3
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for

  • How to Set my own Character Set in DBMS_LOB Package

    Hello All A Very Good Morning. I am using DBMS_LOB.CONVERTTOCLOB To convert data in BLOB to CLOB. My Database Character set is AL32UTF8. I want to change that one to WE8ISO8859P15. In DBMS_LOB.CONVERTTOCLOB package there is a parameter BLOB_CSID. In

  • IMessage on iPad after update

    Anyone elese having a problem with iMessage on iPad after update? Attempting to login says that my internet connection is bad but all other functions working on ipad

  • Function module to execute a Tcode

    Hi, Can any one tell me how I can call a ZTcode in a function module and execute it.. Any example???

  • Live type - artifacts some times

    I have a half dozen live type titles all developed from the same basic set of elements- only differeing in the language on the titlesThe first set i place weeks ago they are all fine, this week i simply copied them and pasted them in another area of

  • System requirements recorder utility

    I wondered what my pc should have from hardware in order to record (sometimes view) multiple cameras with the free recording and monitoring utitly provided with th wvc200. its recorded as mpeg-4 resolution 320x244 fixed quality 30f/s thx