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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:24:44+00:00 2026-06-01T14:24:44+00:00

I have 3 tables I am working with. TableA, TableB, TableC TableA contains the

  • 0

I have 3 tables I am working with.

TableA, TableB, TableC

TableA contains the information for the client, each row contains all the information for one specific person.

TableB contains information for a message a person in TableA created.

ID  DistID  Subject Message CreatedDate StatusID    SentTotal
57  3   MonList MonList 2012-03-19 16:21:36.117 2   4

TableC contains a list of people who have access to the message in TableB.

ID     MessageID    DistID  StatusID  Important  OriginalMessagelID
25111   58            516       1          0       NULL
25112   58            519       1          0       NULL
25114   58            374       1          0       NULL
25115   58            5545      1          0       NULL
25116   58            23435     1          0       NULL

TableC MessageID will be the same as TableB ID.

TableB and TableC DistID will reference the DistID in TableA (table A included way to much info to copy for even a single row, it is a 1 to 1 ratio, 1 row for one customer).

I need to produce a query that links these three tables together. Here is what I have so far:

SELECT *
FROM Distributor d
INNER JOIN Messages ms
    ON ms.DistID = d.DistID
INNER JOIN Message m
    ON m.DistID = d.DistID
WHERE ((d.DCLoginDate <= (GETDATE() - 3) OR d.DCLoginDate IS NULL) AND (CONVERT(VARCHAR(8), m.CreatedDate, 1)) = (CONVERT(VARCHAR(8), GETDATE(), 1)))

Now TableB can have multiple messages created by the same customer, so their DistID can be present in this table more than 1 time.

TableC is the same way, the DistID can be present in this table more than one time.

I started making individual queries that worked:

SELECT *
FROM Distributor
WHERE (DCLoginDate <= (GETDATE() - 3) OR DCLoginDate IS NULL)

SELECT *
FROM Message m
INNER JOIN Messages ms
    ON ms.MessageID = m.ID
WHERE ((CONVERT(VARCHAR(8), CreatedDate, 1)) = (CONVERT(VARCHAR(8), GETDATE(), 1)))

The above work correctly, when I tried to combine them into one statement, it started returning 0 results when i should have returned two (from my live data, not the data provided above).

Anyone understand how to get this to work effeciently?

  • 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-01T14:24:45+00:00Added an answer on June 1, 2026 at 2:24 pm

    Your join conditions were different between the single query and the individual queries… What about this?

    SELECT *
    FROM Distributor d
    INNER JOIN Messages ms
       ON ms.DistID = d.DistID
    INNER JOIN Message m
       ON m.ID = ms.MessageID
    WHERE 
       ((d.DCLoginDate <= (GETDATE() - 3) OR d.DCLoginDate IS NULL) AND 
       (CONVERT(VARCHAR(8), m.CreatedDate, 1)) = (CONVERT(VARCHAR(8), GETDATE(), 1)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working Stripes framework. I have a table which contains 100's of rows
OK, so I have two tables I'm working with - project and service ,
I'm working on databases that have moving tables auto-generated by some obscure tools. By
I am working on PHP and database MySQL. I have two tables in SQL
I am working with some tables where I want the C# class to have
I have an SQL database with multiple tables, and I am working on creating
I have a draggable table which all working fine, though I want to be
We have an application that creates a number of Visual Foxpro (DBF) tables. Each
I'm working on an application for one of our departments that contains medical data.
My company is working with 3 partners and each partner can have multiple brands.

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.