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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:55:59+00:00 2026-06-12T16:55:59+00:00

I have customers table and a another one for the sales activities associated to

  • 0

I have customers table and a another one for the sales activities associated to them (phone calls, emails ecc).
What I need is to know is which of those customers haven’t been contacted (without activities) over the last 30 days for example.

Here is what I’m trying to do:

SELECT crm_customers.id, crm_ customers.companyname
FROM crm_ customers 
LEFT JOIN crm_activities on crm_customers.id = crm_ activities. Customerid
WHERE crm_ activities.createddate < (getDate() – 30)

The problem is that it returns the customers with activities older than 30 days even if they have more recent activities. I need to get only the customers without any sales activities in the last 30 days
Thanks for your help

  • 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-06-12T16:56:00+00:00Added an answer on June 12, 2026 at 4:56 pm
    SELECT crm_customers.id, crm_customers.companyname
    FROM crm_customers 
    LEFT JOIN crm_activities 
      on crm_customers.id = crm_activities.Customerid
     and DATEDIFF(DD, crm_activities.createddate, getdate()) < 30
    where crm_activities.Customerid is null
    

    This is a case of condition in the join is different than condition in the where

    For speed I would suspect the join over the subquery. It gives the query optimizer more option to optimize. Does not required a distinct. Assume crm_activities.Customerid is indexed this is joining on the index. With the subquery it would use the index to create the list but output of the subquery is not indexed.

    Will depend on you datar. I had a big table to test on.

    Query plans are different.

    On a loop join it was dead heat
    On a hash join twice as fast
    On a merge join ten times as fast

    If none are excluded then it will be a dead heat.
    Where it will show up is if many are excluded (have been contacted in the last 30).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a Customers table and an Orders table with a one-to-many
Lets say I have one table called REVIEWS This table has Reviews that customers
I have a self-referencing table (Customers) and a table that will link to one
I have a customers table, and an orders table. Each customer can have many
I have a Customers table and would like to assign a Salesperson to each
If I have a Customers table linked to an Orders table, and I want
I have a table Customers with a CustomerId field, and a table of Publications
I have a table of customers with a 1 recorded against their customerid on
I have a Model created with a table called Customers. It contains the following
Say we have customer table which has record CustId LastName 1 Hamlin In one

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.