| | |
retrieve user's nick and latest title according to dateposted
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Solved Threads: 0
Hi all
i have 2 DBs: Energy & Users
Users:
-id (pk)
-nick
Energy:
-id (pk)
-title
-userid (fk)
-dateposted
Description of workflow:
there are a number of titles in "Energy", and each user has more than 1 titles.
I would like to display Users's Nick, and LATEST TITLE (which is according to the dateposted).
How should i do it?
i tried:
select nick, energy.dateposted from users
join energy
on energy.userid = user.id
but the retrieved results = a list of records with the same nicks for few of the records.
something like that..
2007-04-25 11:40:07.000 val
2007-04-25 11:51:49.000 val
2007-04-25 14:36:45.000 val
2007-04-25 16:14:36.000 val
2007-04-25 16:23:42.000 susu
2007-04-25 16:24:20.000 susu
2007-04-25 16:29:24.000 susu
what i want is to have 2 records for this, which is something like..
2007-04-25 16:14:36.000 val
2007-04-25 16:29:24.000 susu
can anyone please help me with this? thanks alot!
i have 2 DBs: Energy & Users
Users:
-id (pk)
-nick
Energy:
-id (pk)
-title
-userid (fk)
-dateposted
Description of workflow:
there are a number of titles in "Energy", and each user has more than 1 titles.
I would like to display Users's Nick, and LATEST TITLE (which is according to the dateposted).
How should i do it?
i tried:
select nick, energy.dateposted from users
join energy
on energy.userid = user.id
but the retrieved results = a list of records with the same nicks for few of the records.
something like that..
2007-04-25 11:40:07.000 val
2007-04-25 11:51:49.000 val
2007-04-25 14:36:45.000 val
2007-04-25 16:14:36.000 val
2007-04-25 16:23:42.000 susu
2007-04-25 16:24:20.000 susu
2007-04-25 16:29:24.000 susu
what i want is to have 2 records for this, which is something like..
2007-04-25 16:14:36.000 val
2007-04-25 16:29:24.000 susu
can anyone please help me with this? thanks alot!
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
it think this should work
MS SQL Syntax (Toggle Plain Text)
SELECT nick, max(energy.dateposted) FROM users JOIN energy ON energy.userid = user.id GROUP BY nick
![]() |
Similar Threads
- MySQL Nested Select Issue (MySQL)
- Is SEO a part of your business plan? (Search Engine Optimization)
- ASP.NET how can i display the logod user Status (ASP.NET)
- Login and retrieve user data from database (ASP.NET)
- 166 posts gives you a title as Junior Poster?? (Geeks' Lounge)
- please help! this is urgent> how to retrieve data to my tabpage without using data fo (C#)
- Problems in Dynaform (Form Mail) URGENT HELP (PHP)
Other Threads in the MS SQL Forum
- Previous Thread: text message via sql server 2005 to mobile phone
- Next Thread: database hosting......
Views: 1236 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last autogrowth business connectingtodatabaseinuse count cursor data database dateadd datepart day" dbsize deadlock delete_trigger exploit getdate hack highperformancecomputing hpc hpcserver2008 ibm iis limit live loop maximum microsoft ms mssql multiple multithreading news number password permission position query reporting result security server services sets single source sql sql-injection sqlserver sqlserver2005 subtype supercomputing supertype tables uniqueid update view weekday





