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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:05:46+00:00 2026-05-29T23:05:46+00:00

I haven’t been able to solve this problem for several days now and I’m

  • 0

I haven’t been able to solve this problem for several days now and I’m hoping you can help.

I’m trying to write a query that returns all the information about a stock and the last time it was updated. I would like to filter the results based on the parameter @date and return only the stocks which it’s latests update is less than the supplied @date parameter. I also need the stocks with a timestamp of null so I know that theses stocks need to be updated. I have the follwing three tables that I’m working with:

stocks
- id
- asset_id
- market_id
- name
- symbol
- IPOYear
- sector
- industry

updates
- id
- [timestamp]

stock_updates
- stock_id
- update_id

I’ve been using the following query and it was working well for me until I realized it dosen’t work if the stock doesn’t have an update

select * from stocks s
where @date < (
    select top 1 u.timestamp from
        updates u,
        stock_updates su
    where
        s.id = su.stock_id and
        u.id = su.update_id
    order by u.timestamp desc
)

So after some research I came accross outer joins and I think it’s what I need to fix my problem I just haven’t been able to construct the correct query. The closest I’ve come is the following, but it returns a record for each time the stock was updated. Thanks in advance for your help!

This is where I’m at now:

select * from stocks s 
left outer join stock_updates su on s.id = su.stock_id 
left outer join updates u on u.id = su.update_id 
where u.[timestamp] < @date
  • 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-29T23:05:47+00:00Added an answer on May 29, 2026 at 11:05 pm
    select s.*, u.timestamp
    from stocks s 
    left join 
    (select  su.stock_id, MAX(u.timestamp) timestamp
    from updates u 
    inner join stock_updates su 
    on u.id = su.update_id
    group by su.stock_id
    ) as u
    on s.id = u.stock_id
    where u.[timestamp] is null or u.[timestamp] < @date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't been able to solve this prolog exercise. I was hoping someone here
I haven't seen this question anywhere else, I hope someone can help. I have
I haven't been able to find what these Xcode icons mean. Some you can
I haven't been able to find much about this but am I the only
I have a jquery bug and I've been looking for hours now, I can't
I haven't worked with SQL Reporting much, however I have been trying to get
Haven't been programming in JS for a while. Now, I have following thing: <html>
I haven't used the implements keyword before, and I've been trying to use it
I haven't been able to find authorative explanations, microformats or guidelines for the following,
I haven't found any information on MSDN regarding this problem. If we create an

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.