I have Waybill Table in which the joborderID is foreign key of Joborder Table in joborder Table there is FleetTypeID which is the ForeignKey of FleetTypeID and in FleetType Table there are two more foreign key ItemsID and FleetTypeItemsID
The problem is I want to retrieve joborder_table data in waybill_table but the foreign keys in joborder_table are not joining
select DISTINCT FleetTypeItem as Fleet_Items, ItemsName as Items
inner join FleetTypeTbl on FleetTypeItemTbl.FleetTypeItemID=FleetTypeTbl.FleetTypeItemID and
You need to separate out your joins. Also, if those columns are present in multiple tables, you have to reference the table in your select so it knows where to look:
SELECT DISTINCT FleetTypeItemTbl.FleetTypeItem as Fleet_Items, ItemsTbl.ItemsName as Items FROM FleetTypeItemTbl INNER JOIN FleetTypeTbl ON FleetTypeItemTbl.FleetTypeItemID = FleetTypeTbl.FleetTypeItemID INNER JOIN ItemsTbl ON ItemsTbl.ItemsID = FleetTypeTbl.ItemsID
INNER JOIN that
ON something, then
INNER JOIN that onto something else.
So, rather than say
FROM 1, 2, and 3 ON these joins, say
FROM 1, JOIN 1 = 2, JOIN 2 = 3. ...if that makes sense.
It might also make things more readable to alias your tables like this:
SELECT DISTINCT FTI.FleetTypeItem as Fleet_Items, I.ItemsName as Items FROM FleetTypeItemTbl FTI INNER JOIN FleetTypeTbl FT ON FTI.FleetTypeItemID = FT.FleetTypeItemID INNER JOIN ItemsTbl I ON I.ItemsID = FT.ItemsID