Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9099109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:31:53+00:00 2026-06-17T00:31:53+00:00

i am facing a strange issue, if i am checking the mysql query with

  • 0

i am facing a strange issue, if i am checking the mysql query with PHP then i didn’t get the exact result according to mysql query.

But the same query if i run then i get the expected result, here is mysql query:

SELECT id, follow_up_datetime, followed_by, follow_up_status, case_time_zone, description, case_id
FROM case_note
WHERE TYPE LIKE '%follow-up-open%'
AND (
    follow_up_datetime LIKE '%2013-01-08%'
    OR date( follow_up_datetime ) < '2013-01-08'
)
AND follow_up_status <= '1'
GROUP BY case_id
ORDER BY case_id DESC
LIMIT 0 , 30

the result of this query is :

mysql_result

but when i use the same query with php then i get the the wrong ids:
PHP

//current date is "2013-01-08";
$follow_q = "SELECT id, follow_up_datetime, followed_by, follow_up_status, case_time_zone, description, case_id
                 FROM case_note
                 WHERE `type` LIKE '%follow-up-open%'
                 AND (
                 follow_up_datetime LIKE '%$current_date%'
                 OR date(follow_up_datetime) < '$current_date'
                 )
                 AND follow_up_status <= '1' 
                 GROUP BY case_id 
                 ORDER BY case_id DESC";
$follow_r = mysql_query($follow_q) or die('Error in Query!<br />' . mysql_error());

this query providing me the id’s like 53, 84, 47, 36.

last three id’s are correct but the first is not correct. i want first id is 139. Can anyone please help to find out the exact problem?

UPDATE: here i have update the result of id 53

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:31:54+00:00Added an answer on June 17, 2026 at 12:31 am

    A few tips concerning your query itself:

    Your follow_up_datetime should be a type timestamp or datetime

    You don’t need the LIKE operator in your date condition.

    DATE( `follow_up_datetime` ) = '2013-01-08' 
    OR 
    DATE( `follow_up_datetime` ) < '2013-01-08' 
    

    This can be shortened into

    DATE( `follow_up_datetime` ) <= '2013-01-08' 
    

    If you always compare to the current date, you can use CURRENT_DATE

    DATE( `follow_up_datetime` ) <= CURRENT_DATE
    

    Don’t compare a col of type int to a string which will force MySQL to cast all values of the col follow_up_status to string.

    `follow_up_status` <= 1
    

    Are you sure you need LIKE for the type condition?

    `type` = 'follow_up_open'
    

    Would be much faster.

    PHP documentation about the MySQL extension:

    This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.


    EDIT:

    Just realized you GROUP BY case_id.
    If both, id 53 and id 139 have the same case_id MySQL needs to know which row can be discarded. If you don’t give this information, one of the two rows is discarded more or less randomly.

    To work around this problem use a aggregate function. in your case MIN() would deliver the desired result.

    The whole query cleaned up using PHP heredoc notation:

    $follow_q = <<< EOQ
        SELECT 
            MIN( `id` ) AS `id`,
            `follow_up_datetime`,
            `followed_by`,
            `follow_up_status`,
            `case_time_zone`,
            `description`,
            `case_id`
        FROM
            `case_note`
        WHERE
            `type` = 'follow-up-open'
             AND
            `follow_up_datetime` <= '{$current_date}'
            AND
            `follow_up_status <= 1
        GROUP BY 
            `case_id`
        ORDER BY 
            `case_id` DESC
    EOQ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a strange issue.It is working well with outlook 2K3 but not
I am facing strange issue with our WCF service. The same code was working
I am facing a strange issue of different behavior of a same web application
I'm currently facing a strange issue whereby I did not get any errors from
I am facing a very strange issue. I get an error Object Reference Not
I'm facing a strange issue, I'm trying to localize a website, so i converted
I'm facing a rather strange Issue when trying to load data from an XML-Webservice.
I am facing a very strange issue. I have a SharePoint webpart that displays
I'm facing kind of a strange issue which is related MD5-Hashes in Java and
I am using org.apache.log4j.RollingFileAppender and facing strange issue. When I set log file name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.