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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:47:05+00:00 2026-05-26T06:47:05+00:00

I have two tables. They are linked together with a userid. What i wanted

  • 0

I have two tables. They are linked together with a userid. What i wanted do is check if there’s a linked record in table 2 AND if a date field in that table is older then a certain time OR if there’s no linked record in the 2nd table.

I thought i wanted a left join, but it’s ignoring the date field. If there are no records in the 2nd table, then i want to ignore the 2nd table. But if there is a matching record in the 2nd table and the date is outside of my range, then i dont want to select those records.

SELECT FirstName, Email, u.userid FROM u
LEFT JOIN uevh
ON u.UserID = uevh.UserID AND uevh.LastEmailed < GETDATE()-14
WHERE u.ConfirmedEmail = 0

if i run that, and there’s a record in the uevh table that’s less then 14 days old, i dont want a record returned, but it’s returning a record regardless of the 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-26T06:47:06+00:00Added an answer on May 26, 2026 at 6:47 am
    SELECT u.FirstName
         , u.Email
         , u.userid 
    FROM u
    WHERE NOT EXISTS
            ( SELECT *
              FROM uevh
              WHERE u.UserID = uevh.UserID
                AND NOT (uevh.LastEmailed < GETDATE()-14)
            )
      AND u.ConfirmedEmail = 0 
    

    or:

    SELECT u.FirstName
         , u.Email
         , u.userid 
    FROM u
    WHERE ( EXISTS
            ( SELECT *
              FROM uevh
              WHERE u.UserID = uevh.UserID
                AND uevh.LastEmailed < GETDATE()-14
            )
         OR NOT EXISTS
            ( SELECT *
              FROM uevh
              WHERE u.UserID = uevh.UserID
            )
          )
      AND u.ConfirmedEmail = 0 
    

    or:

    SELECT u.FirstName
         , u.Email
         , u.userid 
    FROM u
      LEFT JOIN uevh
        ON u.UserID = uevh.UserID 
    WHERE u.ConfirmedEmail = 0
      AND ( uevh.LastEmailed < GETDATE()-14
         OR uehv.UserID IS NULL
          )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that have virtually identical content and very similar structure. They
I have two tables. Lets say they look like this Table Sports: Column 1:
I have two tables in APEX that are linked by their primary key. One
I have two entities: User and Notice , they are linked together via the
I have a scenario where there are two tables (tables A and B) linked
I have two tables: Client(id,name,...) Purchase(id,item,date,client_id,...) They have their respective Model, with their validations.
I have two tables linked via a HABTM. countries & networks. They are linked
I have two tables, Property and PropertyMeta. They are linked by the PropertyID value.
I have a mysql database with two tables, bookings and users. They are linked
I have two tables in SQL that I populate into DataTables in C#. They

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.