Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql Select with multiple joins
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01648784
Message ID:
01648787
Views:
32
>Hi,
>
>I need to create a SQL Select that would return the following query:
>
>
>EQUIPMENT.EQUIP_ID, EQUIPMENT.EQUIP_DESC, TRANDETAIL.* FROM TRANDETAIL --- JOINS
>
>
>Structure of tables (simplified):
>
>TRANDETAIL      EQUIP_PK
>                            ORDER_NO
>
>ORDERS            ORDER_NO
>                           EQUIP_ID
>
>EQUIPMENT     EQUIP_ID   Char(15)  - Unique field
>                          EQUIP_PK
>                          EQUIP_DESC Char(40) - Equipment descriptoin
>
>
>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?
>
>TIA

Try
select Eq.Equip_Id, Eq.Equip_Desc, Tr.*

from Equipment Eq INNER JOIN TransDetail Tr on Eq.Equp_Pk = Tr.Equp_Pk
UNION -- this will make result distinct
select Eq.Equip_Id, Eq.Equip_Desc, Tr.*
from TransDetail Tr INNER JOIN Orders Or on Tr.Order_No = Or.Order_No
inner join Equipment Eq ON Or.Orders_Equip_ID = Eq.Equip_ID
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform