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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:34:11+00:00 2026-05-26T21:34:11+00:00

i have two tables, program and event. what i am trying to do is

  • 0

i have two tables, program and event. what i am trying to do is get the closest upcoming event for each program. there exists the possibility however, that a program might have no events attached to it or only events that happened in the past, but i still need the program to show up with an empty value for the event dates, not just go away. so i began implementing an outer join based on what i had googled and found outer apply.

the problem appears to be that i have no access to any of the columns in event, geting the error 'Invalid column name 'start_date'.' (this happens with all three columns, not just start date)

so i either need to learn why i can’t access those columns, or figure out a new way to go about writing the query that returns all programs as well as joins the events table for nearest event/leaves values empty if nothing exists

SELECT 
    p.*, 
    e.type,
    e.start_date,
    e.end_date
FROM 
    program p 
    outer apply (
        select top(1) pk_id from events e where fk_program_id = p.pk_id and end_date >= GetDate()
    ) e
  • 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-26T21:34:12+00:00Added an answer on May 26, 2026 at 9:34 pm

    You’re not returning any columns except pk_id from events. Add the other columns to your select statement. 🙂

    SELECT TOP(1) p.pk_id, 
                  TYPE, 
                  start_date, 
                  end_date 
    FROM   events e 
    WHERE  fk_program_id = p.pk_id 
           AND end_date >= Getdate() 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a table recording views of programs. Each program can have two different
I have two tables that are joined together. A has many B Normally you
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables say, t1 and t2 that have t1.t1_id and t2.t2_id as
I currently have two tables similar to users and programs that are linked through
I have two database tables. One table stores data for a commitment that a
I have a program in access that is using some linked ODBC tables. I
My program that I am writing's purpose arose with this issue: There are two
I'm trying to get a query to compare two tables by LEFT OUTER JOINing
I have two tables, Book and Tag , and books are tagged using the

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.