www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > SQL

    SQL For all Structured Query Language, and general database questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-01-2009, 07:39 PM
    DanUK's Avatar
    DanUK DanUK is offline
    Web Developer.
     
    Join Date: Mar 2003
    Location: Somewhere on Planet Earth, I hope.
    Posts: 975
    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 have also tried adding "LIMIT 1" to it, to no avail.

    I hope this makes sense, and thanks!
    __________________
    Kind regards,
    Daniel.

    Last edited by DanUK; 11-01-2009 at 08:05 PM.
    Reply With Quote
      #2  
    Old 11-03-2009, 10:45 PM
    DanUK's Avatar
    DanUK DanUK is offline
    Web Developer.
     
    Join Date: Mar 2003
    Location: Somewhere on Planet Earth, I hope.
    Posts: 975
    Can anyone please spare a few moments to help me out? I'm having a nightmare with this query

    Thanks!
    __________________
    Kind regards,
    Daniel.
    Reply With Quote
      #3  
    Old 11-03-2009, 11:04 PM
    ssystems ssystems is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 232
    Did you try to reverse the order and get the first item?

    Code:
    ORDER BY r.dateadded Limit 0,1
    __________________
    Good Luck

    Santos Systems
    Reply With Quote
      #4  
    Old 11-04-2009, 10:24 AM
    DanUK's Avatar
    DanUK DanUK is offline
    Web Developer.
     
    Join Date: Mar 2003
    Location: Somewhere on Planet Earth, I hope.
    Posts: 975
    Thanks for your reply ssystems.

    Unfortunately still the same!
    __________________
    Kind regards,
    Daniel.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    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

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 07:55 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.