Hi all,
Im in the process of modelling a database, a property database to be exact, so this is going to need a good locational mapping system, the first thing to come to mind is the following:
Country
---------------------------------------
CountryID | Name
Region
---------------------------------------
RegionID | CountryID | Name
Town
---------------------------------------
TownID | RegionID | (CountryID) | Name
But I wanted it to be a little more flexible then that, so I thought about
Location
----------------------------------------
LocationID | ParentID | Name
Now, this one works, as I can go in as many levels as I want e.g.
Country, Region, Town, And so on
However, if I wanted to query every property in Town, it would get quite complicated, because each property would have a LocationID, meaning id have to SELECT * FROM Property WHERE LocationID = x, which wouldn't give me the properties in the lower level locations of Town.
So, I thought of having the ID like this:
1,14,205,40
This represents the Id's as they go down the level (country, region, town, and so on)
Now, to get all the properties in town I could SELECT * FROM Property WHERE LocationID LIKE '1,14,205%' Which is fine
However, I also have a requirement (when drilling down) to be able to select only the next level locations, so if I have country and I want to see all the next level (regions) how would I query that?
Sorry if this is just a big mess of confusion, i've been trying to figure it out for a while, if you have any better ways to implement a flexible location mapping system please let me know!
Thanks,
Matt.
Im in the process of modelling a database, a property database to be exact, so this is going to need a good locational mapping system, the first thing to come to mind is the following:
Country
---------------------------------------
CountryID | Name
Region
---------------------------------------
RegionID | CountryID | Name
Town
---------------------------------------
TownID | RegionID | (CountryID) | Name
But I wanted it to be a little more flexible then that, so I thought about
Location
----------------------------------------
LocationID | ParentID | Name
Now, this one works, as I can go in as many levels as I want e.g.
Country, Region, Town, And so on
However, if I wanted to query every property in Town, it would get quite complicated, because each property would have a LocationID, meaning id have to SELECT * FROM Property WHERE LocationID = x, which wouldn't give me the properties in the lower level locations of Town.
So, I thought of having the ID like this:
1,14,205,40
This represents the Id's as they go down the level (country, region, town, and so on)
Now, to get all the properties in town I could SELECT * FROM Property WHERE LocationID LIKE '1,14,205%' Which is fine
However, I also have a requirement (when drilling down) to be able to select only the next level locations, so if I have country and I want to see all the next level (regions) how would I query that?
Sorry if this is just a big mess of confusion, i've been trying to figure it out for a while, if you have any better ways to implement a flexible location mapping system please let me know!
Thanks,
Matt.