0

I have a TABLE like this

unixdatetime INTEGER PRIMARY KEY,  UserId TEXT,  Latitude TEXT    
1505144748                         ABC123        51.6N
1505309523                         ABC123        51.6N
1505320731                         BCD234        51.6N
1505378502                         BCD234        51.6N
1507382309                         BCD234        51.6N

I need to get a one Latitude result for each DISTINCT UserID, so my result would be [(51.691N), (51.691N)]

Im trying

c.execute('select DISTINCT Latitude from TABLE where UserID in (select DISTINCT UserID from TABLE)').fetchall()

But that only gives me 1 result, I understand thats because Im asking for DISTINCT Latitude, I just dont know how to ask SQLite for what Im looking for. max(Latitude) does the same.

2
  • Which 1 result do you want for a user? The most recent? Commented Sep 19, 2017 at 13:59
  • That would be fine Commented Sep 19, 2017 at 14:00

1 Answer 1

1

You could use GROUP BY:

c.execute('select Latitude from TABLE group by UserId')
Sign up to request clarification or add additional context in comments.

1 Comment

OK thanks, thats works, I had not properly understood what group by did and had failed to use it correctly in an earlier try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.