Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Results from four tables even when one is empty

Results from four tables even when one is empty

Results from four tables even when one is empty

There are four tables, all contain info needed in the result

Subscribers table
Subscribers details

List table
List Details

Message table
Message details

Tracking table
Tracking details

There needs to be a result set that includes:
Subscriber details
Message details
List details
AND Tracking details (when they are available)

**Where ListID and MessageID are supplied**

Subscribers will always in in a List (with ListID)

If there are subscribers with NO messages sent to them it still needs to return subscribers.

If there are messages sent to that list of subscribers and no tracking yet, then it still needs to display Subscribers (with NULLs for tracking fields)

And when there are tracking results; display all the info
including Tracking details

Any help will be much appreciated

RE: Results from four tables even when one is empty

Look up INNER JOINs and OUTER JOINs in the help doc for your respective platform.

INNER JOINs require that data be in both tables.
OUTER JOINs require that data be in one of the two tables.

MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog

RE: Results from four tables even when one is empty

Thanks for that Denny, but I still can't get it to work.
Even if I reduce it to two tables, the second (Tracked) may or may not have a row corresponding to the first (Subscribers) determined by the supplied MessageID and the first tables' SubscriberID

So this does not do the trick:


SELECT Subscribers.*, tracked.*
FROM Subscribers LEFT OUTER JOIN tracked
ON Subscribers.SubscriberID = tracked.SubscriberID
WHERE Subscribers.ListID = 1 AND tracked.MessageID = 13
I get a list returned that includes only those Subscribers that have entries in the tracked table I guess because of the AND in the WHERE clause

So how can I get it to return all Subscribers plus data from Tracked if there is a row for that SubscriberID and MessageID?

Cheers smile


RE: Results from four tables even when one is empty

Oh I've done it smile

this is how:


SELECT Lists.ListName, b.campaignID, b.DateOpened, b.CountOpened, b.DateLastOpened AS DLO, a.SubscriberID, a.Name, a.Subscribed, a.Email, a.Format, a.ListID, a.NumClicks, a.MessageLastOpened, a.SubjectMLO
FROM Subscribers a INNER JOIN Lists ON a.ListID = Lists.ListID
LEFT OUTER JOIN (SELECT campaignID, SubscriberID, MessageID, DateOpened, CountOpened, DateLastOpened FROM tracked WHERE MessageID = @messageID) b ON a.SubscriberID = b.SubscriberID
WHERE a.ListID = @listID

I got the ideas from another of your posts Denny - thanks a million

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close