I’ve got table TContractForm with fields idcontract(primary key),idcntrtype(foreign key),date_begin,date_end,cost. Also I’ve got 3 types of contracts:
TRentWhouseContract with fields idcontract,idclient,idpdtwhs
TRentShoppointContract with fields idcontract,idclient,idshoppoint,idshoptype
TRentEquipContract with fields idcontract,idclient,ideq,amount
idcntrtype – type of contract. TContractType – idcntrtype(primary key),idcntrclass(foreign key),name. TContractClass – idcntrclass,name.
I want to create a view with columns
idcontract,idclient,contract_type(name of type),contract_class(name of class),date_begin,date_end,cost.
But my query return nothing(I know I’ve got several contracts in TRentWhouseContract table(other tables has no rows)(it is without idclient because I don’t know how to get the same idclient from different table if some table are empty).
select TCF.idcontract,
--idclient
TCF.date_begin,
TCF.date_end,
TCT.name as [type],
TCC.name as class,
TCF.cost
from TContractForm as TCF,
TRentEquipContract as TREC,
TRentShopPointContract as TRSPC,
TRentWhouseContract as TRWC,
TContractType as TCT,
TContractClass as TCC
where TCF.idcontract = TREC.idcontract or TCF.idcontract = TRSPC.idcontract
or TCF.idcontract = TRWC.idcontract and TCT.idcntrtype = TCF.idcntrtype
and TCT.idcntrclass = TCC.idcntrclass
If I understand correctly, this is what I would do