Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
need last date in table
Old 04-06-2006, 03:25 PM need last date in table
Junior Talker

Posts: 1
Trades: 0
i have two tables called

[Employee] which contains a username, recnum(pk)
[Consumer] which contains recnum(fk), Entrydate, points

one to many relationship... many entries in consumer for same recnum... i need to display the last date the consumer field has for each username...

the dashes are just added for spacing....

[Employee] ----------------------------- [Consumer]
recnum userid ------------------------- recnum ---- Entrydate - points
1-------- bob ----------------------------- 1 -----------1/4/2006 -- 23
2 ------- joe -------------------------------1 -----------1/5/2006 -- 34
3 ------- mary -----------------------------1 -----------2/6/2006 -- 53
4 ------- john ----------------------------- 2 -----------1/4/2006 -- 12
5 --------paul ------------------------------4 -----------1/6/2006 -- 8
-----------------------------------------------2-----------1/9/2006 -- 10

I need to return...
recnum - userid --- lastdate
1 --------- bob ----- 2/6/2006
2 --------- joe ----- 1/9/2006
4 --------- paul ----- 1/6/2006

using mssql , what would my query look like?


Thanks

Last edited by lakeoffire; 04-06-2006 at 03:30 PM..
lakeoffire is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-13-2006, 07:31 AM Re: need last date in table
Skilled Talker

Posts: 79
Location: Devon, England
Trades: 0
Something like this:


SELECT *
FROM employee
INNER JOIN consumer
ON employee.recnum=consumer.recnum
__________________
Please add to my Talkupation if I was helpful. Thanks.


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
paaaaaaaaaa is offline
Reply With Quote
View Public Profile Visit paaaaaaaaaa's homepage!
 
Old 04-14-2006, 03:55 AM Re: need last date in table
sacx13's Avatar
Experienced Talker

Posts: 32
Location: Here
Trades: 0
Quote:
Originally Posted by paaaaaaaaaa
Something like this:


SELECT *
FROM employee
INNER JOIN consumer
ON employee.recnum=consumer.recnum
select * from Employee left join consumer ON employee.recnum=consumer.recnum where employee.recnum=(select recnum from consumer where recnum=employee.recnum order by date desc limit 1);

Regards
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
sacx13 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to need last date in table
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12186 seconds with 12 queries