By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE Reports
([Report_Id] int, [Report_name] varchar(8))
;
INSERT INTO Reports
([Report_Id], [Report_name])
VALUES
(1, 'Income'),
(2, 'Outcomes'),
(3, 'Costs')
;
CREATE TABLE ReportsIpRel
([Ip_Id] int, [Report_Id] int)
;
INSERT INTO ReportsIpRel
([Ip_Id], [Report_Id])
VALUES
(6, 1),
(4, 2),
(5, 2),
(2, 2),
(1, 3)
;
CREATE TABLE InfoProviders
([Ip_Id] int, [Ip_Name] varchar(9))
;
INSERT INTO InfoProviders
([Ip_Id], [Ip_Name])
VALUES
23 rows affected
select r.*, ipr.ip_id, ipr.Ip_Name, q.uery_Id, q.Query_Name from
reports r
left outer join ReportsIPRel rir on r.Report_Id = rir.Report_Id
left outer join InfoProviders ipr on rir.Ip_Id = ipr.Ip_Id
left outer join QueriesIPRel qir on ipr.Ip_Id = qir.Ip_Id
left outer join Queries q on qir.Query_Id = q.uery_Id
where r.Report_Id= '2'
Report_Id | Report_name | ip_id | Ip_Name | uery_Id | Query_Name |
---|---|---|---|---|---|
2 | Outcomes | 4 | Comapny | 3 | shortconn |
2 | Outcomes | 5 | Others | 3 | shortconn |
2 | Outcomes | 2 | People | 5 | grounding |