Question

Here I have an mysql tables with ID, ID_polja, lat, lng: enter image description here

As you can see I want to get first data from unique number so first (lat,lng) with ID_polja =1

first (lat,lng) with ID_polja = 2 ...

But how to run a query for that?

SELECT * FROM koordinate WHERE ID_polja=[1,2,3... n]
Was it helpful?

Solution

Maybe GROUP and ORDER:

SELECT * FROM `koordinate` GROUP BY `ID_polja` ORDER BY `ID` ASC

OTHER TIPS

SELECT * FROM `koordinate` GROUP BY `ID_polja`
SELECT INSTINCT ID_polja, ID, lat, Ing FROM koordinate

Thats the simplest solution. If you would use WHERE ID_polja IN [1,2,3] you would have to count each and every number and it would still select every entry.

SELECT * FROM koordinate GROUP BY ID_polja;

try this

 SELECT * FROM `koordinate` group by ID_polja;

As per my understanding you need unique data of lat and long from multiple ID_polja.

So try below query :-

SELECT * FROM koordinate WHERE ID_polja IN (1,2,3,...N) GROUP BY ID_polja;

OR

If you do not have any where condition you should use below query :-

SELECT * FROM koordinate GROUP BY ID_polja;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top