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 9316463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:37:32+00:00 2026-06-19T02:37:32+00:00

this morning i involved by this query . i wasted my 2 days .

  • 0

this morning i involved by this query . i wasted my 2 days . but not got good solution . I have a mysql query

SELECT l.date_entered, n.date_entered, n.date_modified, n.name, n.parent_id
FROM  `notes` AS n, leads AS l
WHERE n.parent_type =  "Leads" && MONTH( l.date_entered ) =1 && YEAR( l.date_entered ) =2013 &&  
n.parent_id = l.id
ORDER BY n.date_modified ASC 

This is giving me this output:-

date_entered date_entered date_modified         name    parent_id
2013-01-07  2013-01-07    2013-01-07 20:17:44   rahul   100   
2013-01-07  2013-01-07    2013-01-07 22:27:38   rawat   101
2013-01-03  2013-01-07    2013-01-07 23:29:02   rohit   102
2013-01-03  2013-01-07    2013-01-07 23:33:55   mamta   100
2013-01-04  2013-01-08    2013-01-08 06:16:11   kiran   101
2013-01-07  2013-01-08    2013-01-08 07:10:10   ajay    100

Now, I am trying to get the date-modified difference by matching on parent_id e.g.

  1. Starting with 100, search returns another 100 in 4th row. This date-modified the same day, so result = 0
  2. Next search is for 101 which is found in 5th row. This date-modified is 1 day after the previous 101, so result = 1
  3. Next search is for 102, which is not found, so skip it
  4. Next search is for 100, but this has already been found, so skip it
  5. Next search is for 101, but this has already been found, so skip it
  6. Next search is for 100, but this has already been found, so skip it

my output will be such as:-

date_entered date_entered date_modified         name    parent_id   datediff
2013-01-07  2013-01-07    2013-01-07 20:17:44   rahul   100         0
2013-01-07  2013-01-07    2013-01-07 22:27:38   rawat   101         1
2013-01-03  2013-01-07    2013-01-07 23:29:02   rohit   102         not found
2013-01-03  2013-01-07    2013-01-07 23:33:55   mamta   100         skip due to previous match
2013-01-04  2013-01-08    2013-01-08 06:16:11   kiran   101         skip due to previous match 
2013-01-07  2013-01-08    2013-01-08 07:10:10   ajay    100         skip due to previous match
  • 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-19T02:37:33+00:00Added an answer on June 19, 2026 at 2:37 am

    Try this :

    CREATE  TABLE test as 
    (SELECT l.date_entered date1, n.date_entered date2, n.date_modified mod_date, n.name name, n.parent_id parentid
    FROM  `notes` AS n, leads AS l
    WHERE n.parent_type =  "Leads" && MONTH( l.date_entered ) =1 && YEAR( l.date_entered ) =2013 &&  
    n.parent_id = l.id);
    
    select *,
    case 
    when mod_date=b.min_date and count_parent_id>1 then cast( datediff(next_date,b.min_date) as char)
    
    when count_parent_id=1 then 'not found'
    else 'skip due to previous match'
    end datediff
    
     from  
    (SELECT Date1, Date2, mod_date, name, parentid
    FROM  test) as a
    left join 
    
    (select min_date,next_date, count_parent_id, q1.parentid
      from
        (SELECT min(mod_date) min_date, count(parentid) count_parent_id, parentid
        FROM  test 
        group by parentid) q1
       join
        (SELECT min(mod_date) next_date, parentid
        FROM  test 
        where  mod_date not in 
          (SELECT min(mod_date) min_date FROM  test 
          group by parentid)
        group by parentid
        )q2
       on q1.parentid=q2.parentid
    
    ) as b
    
    on a.parentid=b.parentid
    ORDER BY mod_date ASC ;
    
    drop table test;
    

    This works. Check SQL Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Until this morning I did not know it was possible to have JavaScript in
I found out this morning that proc.new works in a class initialize method, but
this morning I came across this code, and I have absolutely no idea what
Good Morning! I am writing a small AJAX application, using this function as a
This morning I lost a bunch of files, but because the volume they were
This morning I tried running a Silverlight 5 App that we have been building
This morning I noticed that some results to our website have been poisoned in
This morning Maven starts complaining with this error: error: multi-catch statement is not supported
Starting this morning my Eclipse indigo have projects and files with gray light color.
This morning i rode chapters 39,40 and 41 of the JEE6 tutorial. But i

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.