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

  • Home
  • SEARCH
  • 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 8128885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:04:49+00:00 2026-06-06T08:04:49+00:00

I suppose this is not so hard but I can not get it. For

  • 0

I suppose this is not so hard but I can not get it.

For example I have table T1:

ID    
-----
1000
1001

And I have table T2:

ID      GROUP  DATE
--------------------------
1000    ADSL   2.2.2012
1000    null   3.2.2012
1000    NOC    4.2.2012
1001    NOC    5.2.2012
1001    null   6.2.2012
1001    TV    7.2.2012

I want to select from T1 only the row that has as GROUP value NOC from T2 but only if NOC group is for the minimum DATE value in T2.

So my result in this case would be only 1001 because for its minimum DATE 5.2.2012 Group is NOC!

I do not want any joins and I can not use default values for IDs (where id=1000 or id=1001) because this is just example of some big table.

Important also is that I can not use t1.id = t2.id because in some application where I am using this I can not write the whole SQL expression but only partial. I can only use id.

I tried something like:

select id 
from t1 
where
   id in (select id from t2 
          where group = 'NOC' 
          and date in (select min(date) from t2 
                       where id in (select id from t1) 
                      )
         )

But this does not work.

I know it seems little confusing but I really can’t use where t1.id = t2.id

Thanks

  • 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-06T08:04:51+00:00Added an answer on June 6, 2026 at 8:04 am

    If T2.ID is a foreign key referencing T1.ID, you don’t really need the T1 table, because all the IDs could be obtained from T2 only:

    SELECT o.ID
    FROM T2 AS o
    WHERE EXISTS (
      SELECT MIN(i.DATE)
      FROM T2 AS i
      WHERE i.ID = o.ID
      HAVING MIN(i.DATE) = o.DATE
    )
    WHERE o."GROUP" = 'NOC'
    

    But if you insist on involving T1, you just need to modify the above like this:

    SELECT *
    FROM T1
    WHERE ID IN (
      SELECT o.ID
      FROM T2 AS o
      WHERE o."GROUP" = 'NOC'
        AND EXISTS (
          SELECT MIN(i.DATE)
          FROM T2 AS i
          WHERE i.ID = o.ID
          HAVING MIN(i.DATE) = o.DATE
        )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying everything I can to get this script to work and
suppose I have this string: some striinnngggg <a href=something/some_number>linkk</a> soooo <a href=someotherthing/not_number>asdfsadf</a> I want
I am afraid this question is not supposed to be asked here but I
I suppose this could apply to any dynamic language, but the one I'm using
I suppose this question is more general than working with COM components. I have
I have like 400 records on my database, suppose this is the first version
How to get generic interface type for an instance ? Suppose this code: interface
This would be hard with pure SQL and I'm REALLY not sure how to
I have seen the reverse of this question quite a few times, but have
Suppose I have a bulleted list like this: * list item 1 * list

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.