|
|||||||
| SQL For all Structured Query Language, and general database questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Getting first reply
Hi guys, I hope you can help me out please.
I am using these queries (replacing a really ugly method in PHP) to find out whether the *first reply* in a 'supportreply' table linking to a 'support' table of tickets were under 24 hours. Using this method I think it's going through every reply, and not just the first one which is causing incorrect reporting. Can anyone help me with getting it to just find the first reply for a ticket id? Code:
$sql = "SELECT COUNT(*) AS `over` FROM supportreply r, support t WHERE user=1 AND r.id_ticket=t.id_ticket AND r.dateadded > t.dateadded AND TIMESTAMPDIFF(SECOND, r.dateadded, t.dateadded)>86400 ORDER BY r.dateadded"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $over_support = $row['over']; $sql = "SELECT COUNT(*) AS `under` FROM supportreply r, support t WHERE user=1 AND r.id_ticket=t.id_ticket AND r.dateadded > t.dateadded AND TIMESTAMPDIFF(SECOND, r.dateadded, t.dateadded)<=86400 ORDER BY r.dateadded"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $under_support = $row['under']; I hope this makes sense, and thanks!
__________________
Kind regards, Daniel. Last edited by DanUK; 11-01-2009 at 08:05 PM. |
|
#2
|
||||
|
||||
|
Can anyone please spare a few moments to help me out? I'm having a nightmare with this query
![]() Thanks!
__________________
Kind regards, Daniel. |
|
#3
|
|||
|
|||
|
Did you try to reverse the order and get the first item?
Code:
ORDER BY r.dateadded Limit 0,1 |
|
#4
|
||||
|
||||
|
Thanks for your reply ssystems.
Unfortunately still the same!
__________________
Kind regards, Daniel. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|