Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql Select with multiple joins
Message
From
05/03/2017 19:46:43
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01648784
Message ID:
01648798
Views:
33
>Here is the SQL Select that I found works. I am not 100% sure it is the correct one but it has no NULL and returns the query. Here is this SQL select:
>
>
>select equipment.equip_id, equipment.equip_desc, trandetail.* from trandetail  
> left join orders on orders.order_no = trandetail.order_no and trandetail.order_no > 0 and LEN(ordersequip_id) > 0
> join equipment on (trandetail.equip_pk > 0 and equipment.equip_pk = trandetail.equip_pk) or 
> (trandetail.order_no > 0 and equipment.equip_id = orders.equip_id) 
>
>
>The key is that I have JOIN EQUIPMENT only once and have it with an OR. If you see anything I am doing wrong, please let me know.
>Thank you.
>

If it works it works... Your SQL does not guarantee embolded part of original text -result is correct only due to the fact that the second (inner) join finds always a matching item for trandetail, which is something you know or is/has to be guaranteed by RI.

To be totally certain would be to do the second join also as left join and check any resulting lines with null or check each line is really mirrored by doing a select count(*) from trandetail where trandetail.pk not in (select result.pk from result)

Not knowing the table stability and need, hard to argue as a necessity ;-)

>>>The challenge is that the SQL Select should select All Records from TRANDETAIL and records
>>>from EQUIPMENT either by the field TRANDETAIL.EQUIP_PK Jointed with EQUIPMENT.EQUIP_PK
>>>or by Joining ORDERS on ORDER_NO and then Joining EQUIPMENT on EQUIPMENT.EQUIP_ID with ORDERS_EQUIP_ID.
>>>Therefore, it looks like I will have the table EQUIPMENT twice and this creates many NULL values.
>>>
>>>Is my explanation too confusing? Any suggestions?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform