Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get newest input for each user from table

Author  Topic 

ChrisLua
Starting Member

2 Posts

Posted - 2014-11-20 : 09:59:34
Hello!

I dont know how to get the newest input for each user from one single table.
Shoult be a very simple task but i cant work it out.

The table looks like this:
ID (A_I), userID, ip, date(timestamp)

Here is a SQL Fiddle Link with some data also:
http://sqlfiddle.com/#!2/e0a96

i have tryed a lot querys like this one:
SELECT userID, ip FROM userips GROUP BY userID ORDER BY ID DESC
But this one does not give me the latest ip which was entered by a user.

may someone help me with this?

malpashaa
Constraint Violating Yak Guru

264 Posts

Posted - 2014-11-20 : 10:57:31
Try something like this:

SELECT UIP.userID, UIP.ip, UIP.date
FROM userips AS UIP
WHERE UIP.date = (SELECT MAX(UIP2.date)
FROM userips AS UIP2
WHERE UIP2.userID = UIP.userID);


--
Muhammad Al Pasha

For us, there is only the trying. The rest is not our business. ~T.S. Eliot
Go to Top of Page

ChrisLua
Starting Member

2 Posts

Posted - 2014-11-20 : 11:07:45
So this never was a trivial task?
Ok. I'll do it your way.

Thank you.

Any other suggestions are also wellcome :)
Go to Top of Page
   

- Advertisement -