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

The Archive Base Latest Questions

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

OK, I stumped as to why I’m getting the following behavior. I’ve got a

  • 0

OK, I stumped as to why I’m getting the following behavior.

I’ve got a “transaction header” table and “transaction detail” table. For a certain function, the detail table requires a bit of normalization to extract “Remark” data. Each detail record can have up to 3 remarks in it designated by the TranRemark1, TranRemark2 and TranRemark3 columns.

I put together the following query thinking it would work, but it returns the incorrect number of records.

SELECT  
b.ClientName,
a.TranID,
a.TranRemark1,
a.TranDateOfService,
a.TranPayment   
FROM
(select TranRemark1, TranID from TranDetail
union all
select TranRemark2, TranID from TranDetail
union all
select TranRemark3, TranID from TranDetail) AS a
LEFT JOIN TranHeader AS b ON
b.TranID = a.TranID
WHERE a.TranRemark1 = @RemarkCode;

The result set I get is based on the number of TranHeader records that match the ClientName NOT the number of records that match the where clause from TranDetail. For example, if Client “Acme Inc.” has 3 records in the header table and I use the above query for remark code “1234” (which matches only 1 record in TranDetail) the result set lists the correct record 3 times.

EDIT
So I’d expect from the above example to get a result set like this:

ClientName--TranID--TranRemark1--TranDateOfService--TranPayment
Acme Inc    ADC11   1234         8-16-2011          45.11    

What I get is this:

ClientName--TranID--TranRemark1--TranDateOfService--TranPayment
Acme Inc    ADC11   1234         8-16-2011          45.11    
Acme Inc    ADC11   1234         8-16-2011          45.11  
Acme Inc    ADC11   1234         8-16-2011          45.11  

Keep in mind that there can be multiple records for a client in TranHeader.

I’ve tried right and full join, but it all comes out the same.

Where am I missing the problem?

Thanks for the help.

  • 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-24T17:59:39+00:00Added an answer on May 24, 2026 at 5:59 pm

    Can you try replacing:

    LEFT JOIN TranHeader AS b ON
    b.TranID = a.TranID
    WHERE a.TranRemark1 = @RemarkCode;
    

    with:

    LEFT JOIN
      ( SELECT DISTINCT
            TranId, ClientName
        FROM TranHeader
      ) AS b ON
    b.TranID = a.TranID
    WHERE a.TranRemark1 = @RemarkCode;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stumped. Let's say I've got a table, '1', with three columns, 'A', 'B',
This one has me stumped. I've got a java.sql.ResultSet and I'm pulling string values
I've been stumped with some SQL where I've got several rows of data, and
I'm stumped with how to do the following purely in MySQL, and I've resorted
I'm stumped by pivoting a table and the frustration level is rising. I realize
I'm a bit stumped on this one. I had a completely working 2 Node
Really stumped on this one. I have the following PHP file with a variable
/*I got stumped within my code. I think classes will be simpler than structures,
I am a bit stumped on this. Basically I have two tables: Page: id
I'm stumped with this query. I have a deal table with deals for different

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.