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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:40:48+00:00 2026-05-17T18:40:48+00:00

I have a table svn1: id | date | startdate 23 2002-12-04 2000-11-11 23

  • 0

I have a table svn1:

id | date | startdate

23 2002-12-04 2000-11-11
23 2004-08-19 2005-09-10
23 2002-09-09 2004-08-23

select id,startdate from svn1 where startdate>=(select max(date) from svn1 where id=svn1.id);

Now the problem is how do I let know the subquery to match id with the id in the outer query. Obviously id=svn1.id wont work. Thanks!

If you have the time to read more:

This really is a simplified version of asking what I really am trying to do here. my actual query is something like this

    select 
          id, count(distinct archdetails.compname) 
    from 
          svn1,svn3,archdetails 
    where 
          svn1.name='ant' 
      and svn3.name='ant' 
      and archdetails.name='ant' 
      and type='Bug' 
      and svn1.revno=svn3.revno 
      and svn3.compname=archdetails.compname 
      and 
          ( 
            (startdate>=sdate and startdate<=edate) 
            or 
            (
             sdate<=(select max(date) from svn1 where type='Bug' and id=svn1.id) 
             and 
             edate>=(select max(date) from svn1 where type='Bug' and id=svn1.id)
            ) 
            or 
            (
             sdate>=startdate 
             and 
             edate<=(select max(date) from svn1 where type='Bug' and id=svn1.id)
            ) 
          )  
      group by id LIMIT 0,40;

As you notice select max(date) from svn1 where type='Bug' and id=svn1.id has to be calculated many times.

Can I just calculate this once and store it using AS and then use that variable later. Main problem is to correct id=svn1.id so as to correctly equate it to the id in the outer table.

  • 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-05-17T18:40:48+00:00Added an answer on May 17, 2026 at 6:40 pm

    I’m not sure you can eliminate the repetition of the subquery, but the subquery can reference the main query if you use a table alias, as in the following:

    select id,
           count(distinct archdetails.compname)
    from svn1 s1,
         svn3 s3,
         archdetails a
    where s1.name='ant' and
          s3.name='ant' and
          a.name='ant' and
          type='Bug' and
          s1.revno=s3.revno and
          s3.compname = a.compname and
          ( (startdate >= sdate and startdate<=edate) or
            (sdate <= (select max(date)
                         from svn1
                         where type='Bug' and
                               id=s1.id and
             edate>=(select max(date)
                       from svn1
                       where type='Bug' and
                       id=s1.id)) or
            (sdate >= startdate and edate<=(select max(date)
                                              from svn1
                                              where type='Bug' and
                                              id=s1.id)) )
    group by id LIMIT 0,40;
    

    Share and enjoy.

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

Sidebar

Related Questions

I have table tree. I have query: SELECT * FROM tree WHERE pid =10
I have table data, select * from tbltaxamount ; id | taxname | taxinfoid
I have table with 300 000 records (MyISAM). I get record from this table
I have table View with grouped style with three sections. Get information from dictionary
I have table with two columns (varchar from, varchar to). This table represents connections
I have table the following data structure in SQL Server: ID Date Allocation 1,
I have table view which is populated from an array grabbed from a url.
I have table like below ID User Date Location 1 Tom 6-Mar-2012 US 2
I have table TB1 which has the following cols: ID | date --------------------- 1
I have table rows of data in html being filled from a CGI application.

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.