DBAsupport.com Forums - Powered by vBulletin
Results 1 to 8 of 8

Thread: outer join on subquery

  1. #1
    Join Date
    May 2003
    Posts
    18

    outer join on subquery

    Hi everybody --

    Please bear with me as I haven't been at this very long.

    How can I get around this error?
    Code:
      and m.dte_occurred = (select max(dte_occurred) from co_clarification aaa where aaa.sak_csr = a.sak_csr)(+)
                                                                                                             *
    ERROR at line 10:
    ORA-00933: SQL command not properly ended
    Thanks a heap!!

  2. #2
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Post the entire SQL statement.

    Tamil

  3. #3
    Join Date
    May 2003
    Posts
    18
    Code:
    SELECT 
      a.sak_csr as EXTERNAL_ID,
      SUBSTR(m.dsc,1,50) as clar 
    FROM 
      co a,
      co_clarification m 
    WHERE 
      a.sak_csr = 1340
      and a.sak_csr = m.sak_csr
      and m.dte_occurred = (select max(dte_occurred) from co_clarification aaa where aaa.sak_csr = a.sak_csr)(+)  
    ORDER BY external_id
    Thanks!

  4. #4
    Join Date
    May 2003
    Posts
    18
    Code:
    SELECT 
      a.sak_csr as EXTERNAL_ID,
      SUBSTR(m.dsc,1,50) as clar 
    FROM 
      co a,
      co_clarification m 
    WHERE 
      a.sak_csr = 1340
      and a.sak_csr = m.sak_csr
      and m.dte_occurred = (select max(dte_occurred) from co_clarification aaa where aaa.sak_csr = a.sak_csr)(+)  
    ORDER BY external_id
    Thanks!

  5. #5
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    can you describe what you are trying to do?
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  6. #6
    Join Date
    May 2003
    Posts
    18
    Sure!

    I'm trying to select an id and a date that is associated to it, if there is one. In table m, there can be multiple dates associated with one id, so I want the latest one available.

    The reason that I'm joining two tables, even though the id is a column in table m, is that this is part of a bigger query (that currently works).

    I think this is an outer join, because I still want to return the id, even if there is no date for it in table m. But since table m can have more than one row with the same id and I just want the most recent one, I need my subquery. Right? Isn't that what the error msg is saying? How can you do an outer join in conjunction with a subquery?

    Am I totally off?

    Thanks!!

    [BTW, sorry about posting the same response twice. I hit the back button on the browser and it resubmitted my reply. :( ]

  7. #7
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    This would do it, i think.

    Code:
    Select 
       co.sak_csr as external_id,
       (select
          max(dte_occurred)
        from
          co_clarification cc
        where cc.sak_csr = co.sak_csr) as clar 
    From 
      co
    Where 
      co.sak_csr = 1340
    Order By
      external_id
    /
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  8. #8
    Join Date
    May 2003
    Posts
    18
    slimdave --

    You're absolutely right -- that's it. Thanks so much!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width