Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Oracle LEFT JOIN and SUBQUERY error: ORA-00905: missing keyword

Asking for your help on this Oracle query. It's giving me the error 2 "ORA-00905: missing keyword". It was working fine before I added the LEFT JOIN statement. Obviously it won't deliver the information as we need it without the LEFT JOIN statement.

Please provide any help to know which keyword is missing in this query

Thanks a lot!:

DB Tables: DW.TICKETS DW.TICKET_ACTLOG

Subquery table: TABLE_RESOLVERS

SELECT 
    TO_CHAR(DW.TICKETS.RESOLVED_TIMESTAMP,'YYYY-MM-DD HH24:MI:SS') AS RESOLVED_DATE, 
    DW.TICKETS.SUBJECT, DW.TICKETS.OWNER_CORE_ID, 
    DW.TICKETS.TICKET_NUMBER, 
    TABLE_RESOLVERS.SUBMITTER AS RESOLVER_CORE_ID 

FROM DW.TICKETS 

LEFT JOIN
    (SELECT 
        TICKET_NUMBER,
        SUBMITTER 
    FROM DW.TICKET_ACTLOG 
    WHERE 
        TYPE = 'Final Resolution' AND 
        (SUBMITTER = 'B02666' OR 
        SUBMITTER = 'R66604') 
    ORDER BY CREATE_TIMESTAMP DESC 
    ) AS TABLE_RESOLVERS 

ON DW.TICKETS.TICKET_NUMBER = TABLE_RESOLVERS.TICKET_NUMBER  

WHERE 
    DW.TICKETS.RESOLVED_TIMESTAMP >= to_date('05-03-2010','dd-mm-yyyy') AND 
    DW.TICKETS.RESOLVED_TIMESTAMP < to_date('8-03-2010','dd-mm-yyyy') AND 
    DW.TICKETS.TICKET_NUMBER LIKE 'TCK%' AND 
    DW.TICKETS.TICKET_NUMBER IN 
        (SELECT TICKET_NUMBER 
        FROM DW.TICKET_ACTLOG 
        WHERE 
            (SUBMITTER = 'B02666' OR 
            SUBMITTER = 'R66604') 
        ) 

ORDER BY DW.TICKETS.CREATE_TIMESTAMP ASC
like image 521
Arturo Avatar asked Apr 02 '10 20:04

Arturo


People also ask

What does (+) mean in Oracle join?

The plus sign is Oracle syntax for an outer join. There isn't a minus operator for joins. An outer join means return all rows from one table. Also return the rows from the outer joined where there's a match on the join key. If there's no matching row, return null.

What is missing keyword in SQL?

ORA-00905: missing keyword. As the message suggests, your code is missing a keyword where there should be one in order for the query to run successfully. The Solution. According to the Oracle documentation, the action for this error is to “correct the syntax.”

What is the use of (+) in SQL?

Performing Outer Joins Using the (+) Symbol In practice, the + symbol is placed directly in the conditional statement and on the side of the optional table (the one which is allowed to contain empty or null values within the conditional).


1 Answers

In Oracle we don't include the AS when declaring a table alias. Instead of

    ) AS TABLE_RESOLVERS 

write

   ) TABLE_RESOLVERS 

This is one example when Oracle syntax is more restrictive than some other flavours of SQL. It is also inconsistent with the declaration of column aliases, which is unfortunate but almost certainly it's too complex to change this far down the road.

like image 65
APC Avatar answered Sep 17 '22 14:09

APC