I have a very large table (few million records). The columns in the table say A are currently like this:
id, road name, lat, lon where id is an auto increment PK.
Currently 1 road name can have multiple entries in the table as each road is mapped to a number of (lat, lon) combination.
What I’m trying to do is make road name as primary key and then remove lat and lon columns. Then add a column of type Geometry which will contain a list of (lat – lon) points that represent the road.
I can easily do this in java + mysql, but what I was wondering was if there is a way to easily do this by writing couple of nested queries? Basically I already have a populated table A and another table B with just road name as PK and a second column of type Geometry. What I want is combine all the lat, lon for each unique road name to a Geometry Point list and insert to table B. Is it possible to do this in mysql?
Note: Don’t worry about uniqueness of road names as this is just an example and not the actual scenario. Thanks!
Update: The concat/group_concat function returns a String. As my column type is Geometry, I just pass this string to GeomFromText() spatial function in MySQL Spatial Extension to get in geometry format.
I think the following query will do what you want:
This will produce the list as comma-separated sublists, in the order the points appear in A.