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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:01:38+00:00 2026-05-24T08:01:38+00:00

I have a few tables that I need to link together to get a

  • 0

I have a few tables that I need to link together to get a specific value, here is my current query

SELECT DISTINCT bu.Email,iv.Code,ex.ExNumber 
FROM Invoices AS iv
INNER JOIN Clients AS cs
ON iv.Code = cs.Code
INNER JOIN BusinessUser_ExNumbers AS ex
ON cs.ExNumber = ex.ExNumber 
INNER JOIN BusinessUsers AS bu
ON ex.Userid = bu.Id
WHERE iv.BatchId = '74b43669-c80f-4b44-999c-a1dfe5695844' // Test value

Basically the links to my invoices are held in the invoice table, and what I need to do is send a link to the user who is specified as being the recipient of the invoice. The code works but it’s not as ‘distinct’ as I would like. I dont want any rows with the same email and exnumber as any other row. Unfortunately if there is more than 1 iv.Code that ends up linking to a specific user I get multiple rows. I understand why this is but I can’t think of a way to make that not happen.

Thanks!

EDIT: Sorry that was really stupid of me. I didn’t need to select the iv.Code and that’s what was causing the issue. That’s probably why it didn’t make much sense. Anyway since I posted the question I have tried Martin Smiths answer below and it works, so that is the answer to the question. If you don’t need the iv.Code it can just be removed.

  • 1 1 Answer
  • 1 View
  • 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-24T08:01:39+00:00Added an answer on May 24, 2026 at 8:01 am

    The below will return the MAX code in the event that there are multiple for a particular Email, Number combination.

    SELECT bu.Email,
           MAX(iv.Code) AS Code,
           ex.ExNumber
    FROM   Invoices AS iv
           INNER JOIN Clients AS cs
             ON iv.Code = cs.Code
           INNER JOIN BusinessUser_ExNumbers AS ex
             ON cs.ExNumber = ex.ExNumber
           INNER JOIN BusinessUsers AS bu
             ON ex.Userid = bu.Id
    WHERE  iv.BatchId = '74b43669-c80f-4b44-999c-a1dfe5695844'
    GROUP  BY bu.Email,
              ex.ExNumber  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few huge tables on a production SQL 2005 DB that need
We have a DB with a few hundred tables that have a CHAR Code
I have several database tables that just contain a single column and very few
I have a query in VBA that Adds a few columns to a table.
I have a few thousand tables in my SQL Server instance, and I need
I have a few database tables that really only require a unique id that
Basically I need to be able to have a few tables for sales of
I have few tables that gather data for internal use but i want to
I've got a few tables that all have the same column domainID which basically
We have 15 audit trail tables that need to be combined to look for

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.