Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 22nd, 2003, 10:01 PM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Equiv to Access LAST() function?

Hi all,

Stumped again! I'm working on a posting forum type thing (normal stuff:
user->picturethreads->picturemessages)
And what I wanted to do was a one query wonder to display list of threads, thread creator, num of messages under thread, last message added to thread date and creator of last message! (phew)

I got it working in Microsoft Access - but didn't realise at the time MySQL doesn't support the Last() statement...

This is what it looks like in Access SQL:
Code:
SELECT picturethreads.thread, users.username, Count(picturemessages.messageid) AS CountOfmessageid, Last(users_1.username) AS LastOfusername, Max(picturemessages.datestamp) AS MaxOfdatestamp, Max(picturemessages.timestamp) AS MaxOftimestamp
FROM ((picturethreads INNER JOIN picturemessages ON picturethreads.threadid = picturemessages.threadid) INNER JOIN users ON picturethreads.userid = users.userid) INNER JOIN users AS users_1 ON picturemessages.userid = users_1.userid
WHERE (((picturethreads.pictureid)=1))
GROUP BY picturethreads.thread, users.username, picturethreads.threadid, picturethreads.datestamp, picturethreads.timestamp
ORDER BY picturethreads.datestamp DESC , picturethreads.timestamp DESC

As you can see I also bring the users table in twice - one on each end of the query flow. The max on the dates and times ensure that I get the most recent message, while the last() function on the username gives me the last user that posted a message.

I'm gonna give up and do two MySQL queries instead - but just wondered if anyone could recommend a way of doing 1 query to get the above???

J

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Equiv to Access LAST() function?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway