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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:57:54+00:00 2026-06-17T15:57:54+00:00

Currently I am performing 3 separate SQL calls. I would like to combine them

  • 0

Currently I am performing 3 separate SQL calls. I would like to combine them into one if possible so my grid will sort properly.

I am working with 4 separate Tables

BlastAnalytics – has the following columns and bold are the ones I need the values…
id(primaryKey), eventType, BlastID, email, ts, bounceDesc

BlastJobs – has the following columns and bold are the ones I need the values…
JobNumber(primaryKey), MessageFrom, MessageHeader

BlastOpens – id(primaryKey), AnalyticsID, ts

BlastClicks – id(primaryKey), AnalyticsID, ts

The Joins are…
BlastAnalytics.BlastID –> BlastJobs.JobNumber
BlastAnalytics.id –> BlastOpens.AnalyticsID
BlastAnalytics.id –> BlastClicks.AnalyticsID

Currently I run the following SQL Statement to bind my grid…

SELECT BlastAnalytics.eventType, BlastAnalytics.BlastID, BlastAnalytics.email, 
  BlastAnalytics.ts, BlastAnalytics.bounceDesc, BlastJobs.MessageFrom, 
  BlastJobs.MessageHeader
FROM BlastAnalytics INNER JOIN
  BlastJobs ON BlastAnalytics.BlastID = BlastJobs.JobNumber
WHERE (BlastAnalytics.eventType <> 'open') 
 AND (BlastAnalytics.eventType <> 'click') 
 AND (BlastAnalytics.BlastID = @BlastID)
ORDER BY BlastAnalytics.ts DESC

Then on grid1_RowDataBound (when each individual row is created) I run the follow statements to get my Counts…

SELECT COUNT(*) AS OpenCount, BlastAnalytics.email
FROM BlastAnalytics INNER JOIN
  BlastOpens ON BlastAnalytics.id = BlastOpens.AnalyticsID
WHERE (BlastAnalytics.BlastID = @BlastID) 
  AND (BlastAnalytics.email = @email)

SELECT COUNT(*) AS ClickCount, BlastAnalytics.email
FROM BlastAnalytics INNER JOIN
  BlastClicks ON BlastAnalytics.id = BlastClicks.AnalyticsID
WHERE (BlastAnalytics.BlastID = @BlastID) 
  AND (BlastAnalytics.email = @email)

This all works fine but I would think I should be able to combine those statements into one using GROUP BYs or something, but I can’t figure out how.

EDIT

Here is an example of the type of data in the tables…

BlastOpens Table

id     AnalyticsID    ts     BlastID
2958   38289   1358546399   479
2959   38852   1358546391   479
2960   38280   1358546391   479
2961   38280   1358546400   479
2965   38282   1358546396   480
2986   38284   1358546398   480

BlastAnalytics Table

id  eventType   BlastID   email   ts   bounceDesc
38280   open   479  blahblah@blah.com   1358546555  NULL
38289   open   479  blahblah@blah.com   1358546555  NULL
38352   open   479  itsa@test.com   1358550528  NULL
38115   send   479  blahblah@blah.com   1358545375  NULL

So in the example above blahblah@blah.com has a total Open Count of 3 and itsa@test.com has 1.

  • 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-17T15:57:55+00:00Added an answer on June 17, 2026 at 3:57 pm

    While I haven’t tested this, something like this should work assuming your RDBMS supports sub queries:

    SELECT BlastAnalytics.eventType, BlastAnalytics.BlastID, BlastAnalytics.email, 
       BlastAnalytics.ts, BlastAnalytics.bounceDesc, BlastJobs.MessageFrom, 
       BlastJobs.MessageHeader, 
       BO.OpenCount,
       BC.ClickCount
    FROM BlastAnalytics 
       INNER JOIN BlastJobs ON BlastAnalytics.BlastID = BlastJobs.JobNumber
       LEFT JOIN (
          SELECT COUNT(*) AS OpenCount, BlastAnalytics.BlastID, BlastAnalytics.email
          FROM BlastAnalytics INNER JOIN
             BlastOpens ON BlastAnalytics.id = BlastOpens.AnalyticsID
          GROUP BY BlastAnalytics.BlastID, BlastAnalytics.email
       ) BO ON BlastAnalytics.BlastID = BO.BlastID AND BlastAnalytics.Email = BO.Email
       LEFT JOIN (
          SELECT COUNT(*) AS ClickCount, BlastAnalytics.BlastID, BlastAnalytics.email
          FROM BlastAnalytics INNER JOIN
             BlastClicks ON BlastAnalytics.id = BlastClicks.AnalyticsID
          GROUP BY BlastAnalytics.BlastID, BlastAnalytics.email
       )  BC ON BlastAnalytics.BlastID = BC.BlastID AND BlastAnalytics.Email = BC.Email
    WHERE (BlastAnalytics.eventType <> 'open') 
       AND (BlastAnalytics.eventType <> 'click') 
       AND (BlastAnalytics.BlastID = @BlastID)
    ORDER BY BlastAnalytics.ts DESC
    

    Good luck.

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

Sidebar

Related Questions

I'd like to determine if a UITableView and other views are currently performing some
I'm currently performing a feasibility study where one of the questions is concerning the
I have some python code that currently performs expensive computation by performing the computation
Currently I'm starting a new Activity and calling finish on a current one. Is
Currently I have 2 ways of displaying images in a cell, which way will
Currently working with converting SQLException error messages into messages that are more useful for
I am performing a count based on a date range. Currently the query does
I've a really poorly performing piece of regex, currently it makes Firefox, Chrome and
I'm performing a transform on the entity objects into my own models (CustomerModel and
I'm performing matrix inversion using Householder transformations acting on an augmented matrix. Currently I

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.