Good morning...
I am trying to run a query that requests the Top 100 (or 200 or whatever based on the user's choice) records from my database. Well to be more specific, I have a streets table and an addresses table. I want the top 100 streets, and all the addresses that correspond to those streets. This is what the statement looks like right now:
SELECT TOP 100 Streets.City, Streets.Name, Streets.Name + ' ' + Streets.Type as Street, Addresses.Address, Addresses.Resident, [addresses.etc...], ESNs.ESN FROM Streets INNER JOIN (Addresses INNER JOIN (Segments INNER JOIN ESNs ON Segments.ESNId = ESNs.Id) ON Addresses.StreetId = Segments.StreetId) ON Streets.Id = Segments.StreetId WHERE Streets.City = "WHITEVILLE" AND Addresses.Address BETWEEN Segments.BAddress AND Segments.EAddress ORDER BY Streets.Name, Addresses.Address
All the joins and everything work as far as I get the proper information for the records that are returned. However, I am getting the wrong records. I am only getting 100 addresses and a couple streets. I want to say
SELECT TOP 100 Streets and all addresses where addresses.streetid = streets.id.
But I can't seem to figure out how to get 100 streets and all related addresses in one sql statement.
Any ideas would be appreciated...Thanks in advance...
I am trying to run a query that requests the Top 100 (or 200 or whatever based on the user's choice) records from my database. Well to be more specific, I have a streets table and an addresses table. I want the top 100 streets, and all the addresses that correspond to those streets. This is what the statement looks like right now:
SELECT TOP 100 Streets.City, Streets.Name, Streets.Name + ' ' + Streets.Type as Street, Addresses.Address, Addresses.Resident, [addresses.etc...], ESNs.ESN FROM Streets INNER JOIN (Addresses INNER JOIN (Segments INNER JOIN ESNs ON Segments.ESNId = ESNs.Id) ON Addresses.StreetId = Segments.StreetId) ON Streets.Id = Segments.StreetId WHERE Streets.City = "WHITEVILLE" AND Addresses.Address BETWEEN Segments.BAddress AND Segments.EAddress ORDER BY Streets.Name, Addresses.Address
All the joins and everything work as far as I get the proper information for the records that are returned. However, I am getting the wrong records. I am only getting 100 addresses and a couple streets. I want to say
SELECT TOP 100 Streets and all addresses where addresses.streetid = streets.id.
But I can't seem to figure out how to get 100 streets and all related addresses in one sql statement.
Any ideas would be appreciated...Thanks in advance...