I have two table that each of them have a column with point (spatial) datatype like this :

Table 1 :

id            latlng
------------------------------
1     POINT(35.72036 51.42124)  
2     POINT(32.74446 53.42124)        
3     POINT(31.78676 51.44564)   
4     POINT(32.73436 54.42124)

Table 2:

id            latlng
------------------------------
1     POINT(35.719 51.4221)   
2     POINT(35.72036 51.42124)        
3     POINT(32.74446 53.42124)   
4     POINT(31.78676 51.44564)    
5     POINT(32.73436 54.42124)                       
6     POINT(35.72379 51.4144) 

Now i want to join these two table in together with LEFT JOIN statement on Table 2

i wrote this query but it returns 24 rows! i should be 6 rows like table 2.

SELECT * FROM Table2 LEFT JOIN Table1 ON Table2.latlng = Table1.latlng

is there any way to resolve this problem & just get 6 rows?

有帮助吗?

解决方案

i think you forgot GROUP BY

try this

 SELECT * FROM Table2 
 LEFT JOIN Table1 
 ON Table2.latlng = Table1.latlng
 GROUP BY Table2.id
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top