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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:31:05+00:00 2026-05-16T21:31:05+00:00

Recently a very friendly user on stackoverflow helped me with this SQL: SELECT (SELECT

  • 0

Recently a very friendly user on stackoverflow helped me with this SQL:

 SELECT (SELECT TOP 1 
                a.id
           FROM vAnalysesHistory AS a 
          WHERE a.companyid = n.stockid 
       ORDER BY a.chosendatetime DESC) AS id,
        n.name, 
        (SELECT TOP 1 
                a.chosendatetime 
           FROM vAnalysesHistory AS a 
          WHERE a.companyid = n.stockid 
       ORDER BY a.chosendatetime DESC) AS chosendatetime
   FROM vStockNames AS n 

Which is working great. Now i want to extend this SQL. In the table vAnalysesHistory there is an attribute called analyseid. I would like to only get rows with analyseid = 3 for example.

My try:

 SELECT (SELECT TOP 1 
                a.id
           FROM vAnalysesHistory AS a 
          WHERE a.companyid = n.stockid AND analyseid = 3
       ORDER BY a.chosendatetime DESC) AS id,
        n.name, 
        (SELECT TOP 1 
                a.chosendatetime 
           FROM vAnalysesHistory AS a 
          WHERE a.companyid = n.stockid AND analyseid = 3
       ORDER BY a.chosendatetime DESC) AS chosendatetime
   FROM vStockNames AS n 

The problem is that there isnt analyses with analyseid = 3 for every row in vStockNames. Therefore some of the rows returned has null in id and chosendatetime.

Can you help me? I only want rows where there exists and analyse with analyseid for example analyseid = 3.

And oh ye, the server is 2000.

Thanks in advance

  • 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-16T21:31:06+00:00Added an answer on May 16, 2026 at 9:31 pm

    I used another approach:

    SELECT     B.id, C.ChosenDateTime, N.name
    FROM         (SELECT     companyid, MAX(chosendatetime) AS ChosenDateTime
                           FROM          vAnalysesHistory AS A
                           WHERE      (analyseid = 3)
                           GROUP BY companyid) AS C INNER JOIN
                          vAnalysesHistory AS B ON C.companyid = B.companyid AND C.ChosenDateTime = B.chosendatetime AND B.analyseid = 3 INNER JOIN
                          vStockNames AS N ON N.stockid = C.companyid
    ORDER BY N.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very recently, I started getting the SQL max user connections limit reached error. I
I recently made a very simple practice program in Python, that takes user input
EDIT 9-3-10: I found this blog entry recently that was very enlightening. http://optimizermagic.blogspot.com/2007/12/outerjoins-in-oracle.html There
Very recently all the new classes I create in Xcode are prefaced by this
This is a strange one as up until very recently this functionality was working
I hope I'm not using stackoverflow.com in the wrong way: asking this question! Recently
I'm coming from a PHP/Python/Javascript background, and recently became very interested in Scala -
It was working fine up until very recently. Chrome tells me this is incorrect
Very recently I've asked this question, but wasn unable to fix this. So I
Very recently I asked this question on how to pass clicks through an element

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.