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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:04:05+00:00 2026-05-31T19:04:05+00:00

I have a dilemma. Let’s assume(for simplicity’s sake) I have four tables, with different

  • 0

I have a dilemma.

Let’s assume(for simplicity’s sake) I have four tables, with different numbers of columns and rows, they are: users, mail, events and service.

When I receive a request, I have an ID that links on three of those tables, but with different columns it matches to.
Let’s say, users matches on user_id, mail matches on user_ref and events matches on user_ref as well.

That would’ve been a fine query for me to write up, even with single, multiple or even all IDs.
The problem arrives on the next step I have to take, and that’s the *service table.

The service table doesn’t conform to the same standards of the others, thus it does not have an user_id, or user_ref that can be pulled.
What it has instead, is a *mail_ref* column, and it has the potential to contain duplicates.
My current method is trying to use an IN() method, but it only works for selecting a single user/row.

Here’s my current query:

SELECT
    u.Name as Name,
    COUNT(m.user_ref) AS Mail_total,
    e.mail_id,
    COUNT(e.user_ref) AS Event_total,
    COUNT(s.mail_ref) AS service_total
FROM
    users u
LEFT JOIN
    mail m ON m.user_ref = u.user_id
LEFT JOIN
    service s ON s.mail_ref IN(e.mail_id)
LEFT JOIN 
    events e ON e.user_ref = u.user_id
WHERE u.user_id IN(my,list,of,ids)
GROUP BY s.mail_ref

The problem I have with it currently, is that although it’s selecting the correct data, it’s not selecting unique data for every id I specify.
It works marginally fine when given a single id, but as mentioned above, not when it has to retrieve multiple rows.

If anyone could help me out it would be much appreciated.

  • 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-31T19:04:06+00:00Added an answer on May 31, 2026 at 7:04 pm

    Do a subquery in the left join for service. Instead of:

    LEFT JOIN
    service s ON s.mail_ref IN(e.mail_id)

    Try

    LEFT JOIN
    (select TOP 1 mail_ref from server) as S on s.mail_ref = e.mail_id

    See if that works.

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

Sidebar

Related Questions

So here is my dilemma: I have a base class (Let's say a generic
In a bit of a dilemma. I have tables Schools , Projects , Sponsors
I have recently came to this dilemma: let's say I want to use two
Dilemma: I have a table with several hundred rows in it. I would like
Let's assume a simple and common scenario. I have a User model with an
I seem to have a dilemma. I have an EXCEL 2003 template which users
I have an interesting dilemma: I've got a class, let's say it's called FileCabinet.
I have a dilemma on my hands. After much trial and error, I still
We have a dilemma; developing desktop application using Matisse or Jigloo.. Matisse has this
I have a dilemma that I've encountered before. What's the best in terms 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.