Hi all,
I'm trying to create a db view in SQL for a web app to use in building a report that I need. The problem is that the query for creating this view is somewhat beyond my current skill level with SQL so I'm having some issues getting it to work.
I need to link a geographical region in a table (geo_regions) to financial data in another table (ls). A colleague helped me out a bit with it so I have all the columns I need in the view the only thing is that data is being duplicated. There should 41 records but I'm getting over 280. There are several tables between geo_region and ls that need to be included and with all the joins being used it's way over my head. The below is the script that was used to create the view
Any help would be greatly appreciated
I'm trying to create a db view in SQL for a web app to use in building a report that I need. The problem is that the query for creating this view is somewhat beyond my current skill level with SQL so I'm having some issues getting it to work.
I need to link a geographical region in a table (geo_regions) to financial data in another table (ls). A colleague helped me out a bit with it so I have all the columns I need in the view the only thing is that data is being duplicated. There should 41 records but I'm getting over 280. There are several tables between geo_region and ls that need to be included and with all the joins being used it's way over my head. The below is the script that was used to create the view
Code:
CREATE VIEW [afm].[za_geo_regn_ls]
AS
SELECT a.geo_region_id, a.geo_region_name, b.ctry_id, b.name AS ctry_name, c.regn_id, c.name AS regn_name, d.state_id, d.name AS state_name, e.city_id, e.name AS city_name, f.site_id, f.name AS site_name, g.pr_id AS pr_pr_id, h.pr_id AS ls_pr_id, g.name AS pr_name_name, h.ls_id, h.amount_base_rent
FROM afm.geo_region AS a LEFT OUTER JOIN
afm.ctry AS b ON a.geo_region_id = b.geo_region_id LEFT OUTER JOIN
afm.regn AS c ON b.ctry_id = c.ctry_id LEFT OUTER JOIN
afm.state AS d ON c.regn_id = d.regn_id LEFT OUTER JOIN
afm.city AS e ON d.state_id = e.state_id LEFT OUTER JOIN
afm.site AS f ON e.city_id = f.city_id LEFT OUTER JOIN
afm.property AS g ON f.site_id = g.site_id LEFT OUTER JOIN
afm.ls AS h ON g.pr_id = h.pr_id
Any help would be greatly appreciated