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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:13:29+00:00 2026-05-26T17:13:29+00:00

I guess this is more a design pattern question than a SQL one. In

  • 0

I guess this is more a design pattern question than a SQL one.

In my application a user can join, can create a shop and load products in their shop (so lets say that there is a user, shop (one to one) and products (many to one with the shops).

So I want to be able to do certain things based on time and criteria (but only once) so for example if one week after joining a user has no shop I want to send an email, or 2 weeks after joining with a shop but no products send a email etc – but I only want to do it once.

Its the only running once which is doing my head in – so for example lets say I had this query

select * from user where joineddt < '1 week ago date'

And I had a script which ran every 3 hours, fires off the SQL and then does whatever event (e.g. send a email) I then want to ensure if this script was fired again it would not pick up any users which have already been processed. I thought of introducing a ‘events’ table where once the event for a user has been fired, log a entry for that event, but that again does not seem to work. For example say I had the events table, had id, user, event

select * from user a
left join event b on b.user = a.id
where a.joineddt < '1 week ago date'
and b.event = 'userjoined'
and b.id is null

So when there is no entry in the events able for the ‘userjoined’ event, it will return no results…But really I want it to return the users where there is no event in event table for this ‘userjoined’ event?

So can anyone think of a way to do what I am suggesting?

  • 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-26T17:13:30+00:00Added an answer on May 26, 2026 at 5:13 pm

    Your query will always return 0 rows, because if b.id is null, b.event can never be ‘userjoined’.
    Move the ‘userjoined’ criteria to the join clause.

    SELECT a.* 
    FROM user a 
    LEFT JOIN event b ON (b.user = a.id AND b.event = 'userjoined') 
    WHERE a.joineddt < '1 week ago date' 
    AND b.id IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess this more of a design question, but I currently have a REST
I guess this is more about SEO than wanting to support browsers with Javascript
This is a design question, I guess there going to be several suggestions (I
I guess this is an odd one, and the answer is most likely it
I guess this is a simple question. I need to do something like this:
I guess this is kind of an odd question but I have tried setting
Okay guess this question looks a lot like: What is the best way to
I guess this is a continuation of the last question I asked: bulk insert
I guess this question will sound familiar, but I am yet another programmer baffled
I have a HashMap (although I guess this question applies to other collections) of

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.