I have three tables with some banners info and i need to select all the banners from all of them by CompanyID.
The tables are:
BannerCompany (AdminMaster.dbo.BannerUnidades)
Banner (AdminMaster.dbo.Banner)
BannerClient (AdminHotSite.dbo.Banner)
The first table (BannerCompany) has CompanyID and BannerID and is linked to the table Banner by BannerID;
The second table (Banner) has BannerID and all the rest of the banner info;
The third table (BannerClient) is another table where i have other banners also with CompanyID and BannerID (This BannerID from table BannerClient is different from the BannerID from table Banner).
What i need is select the banners on BannerCompany and link them with Banner by BannerID with a WHERE on BannerCompany.BannerCompanyID and then select the banners from BannerClient with the same where but now on BannerClient.BannerCompanyID.
Now, i can select the banners from the first and the second but i can't find a way to put the third table on the game.
All the tables have the same columns with the same name.
My code so far:
SELECT * FROM AdminMaster.dbo.BannerUnidades AS bUnidade
INNER JOIN AdminMaster.dbo.Banner AS bMaster ON bUnidade.BannerID = bMaster.BannerID
INNER JOIN AdminHotSite.dbo.Banner AS bHS ON bHS.BannerPrincipal = 1
WHERE bHS.UnidadeCodEmitente = 45471
Thanks in advance.