on 2019 Dec 27 1:43 PM
Can you do a "Join" within a "LEFT OUTER JOIN"? My SQL is:
SELECT ol.plc_id + '|' + CAST(ol.orderlog_nbr AS varchar(12)) AS orderlog_id, ol.seal_type, ol.bag_markings, ol.bag_tag AS tags, ol.charge_inspection_to_id, olbo.discharge_port_serial_nbr, olbo.loading_port_serial_nbr, ol.docs_sent_to_customer_date, CAST(NULL AS varchar(100)) AS instruction_note, ollid.export_document_nbr, ollid.carrier_bol, ollid.phyto_certificate, ollid.inspection_certificate, s1_country.export_declaration_nbr_label FROM s1_orderlog ol LEFT OUTER JOIN s1_orderlog_booking_order olbo ON ol.plc_id = olbo.plc_id AND ol.orderlog_nbr = olbo.order_nbr LEFT OUTER JOIN s1_orderlog_loading_instr_doc ollid ON ollid.orderlog_nbr = ol.orderlog_nbr AND ol.plc_id = ollid.plc_id LEFT OUTER JOIN s1_name_and_address JOIN s1_country ON s1_country.country_code = s1_name_and_address.country_code ON s1_name_and_address.name_and_address_id = ol.origin_id ;
It produces the following error: Could not execute statement. Syntax error near 'ON' on line 26 SQLCODE=-132, ODBC 3 State="42000"
Line 26 is: JOIN s1_country
If you want to embed a join within another join, use parantheses around the "inner" join, such as...
from A left join (B inner join C on B.c1 = C.c1) on A.x = B.x
Without parantheses, joins are interpreted from left to right, so in your case the "JOIN" is not expected because the LEFT JOIN's ON condition is missing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Volker: I modified the SQL as suggested: LEFT OUTER JOIN s1_name_and_address (JOIN s1_country ON s1_country.country_code = s1_name_and_address.country_code ) ON s1_name_and_address.name_and_address_id = ol.origin_id
but it produces the same error.
FYI: Interactive SQL version 17.0.4, build 2053
Always show the exact code you are referring to... always... always... always... always... always... that's 5 "always", the maximum possible 🙂
User | Count |
---|---|
81 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.