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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:57:31+00:00 2026-05-12T00:57:31+00:00

I have a view which was working fine when I was joining my main

  • 0

I have a view which was working fine when I was joining my main table:

LEFT OUTER JOIN OFFICE ON CLIENT.CASE_OFFICE = OFFICE.TABLE_CODE.

However I needed to add the following join:

LEFT OUTER JOIN OFFICE_MIS ON CLIENT.REFERRAL_OFFICE = OFFICE_MIS.TABLE_CODE 

Although I added DISTINCT, I still get a “duplicate” row. I say “duplicate” because the second row has a different value.

However, if I change the LEFT OUTER to an INNER JOIN, I lose all the rows for the clients who have these “duplicate” rows.

What am I doing wrong? How can I remove these “duplicate” rows from my view?


Note:

This question is not applicable in this instance:

How can I remove duplicate rows?

  • 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-12T00:57:32+00:00Added an answer on May 12, 2026 at 12:57 am

    DISTINCT won’t help you if the rows have any columns that are different. Obviously, one of the tables you are joining to has multiple rows for a single row in another table. To get one row back, you have to eliminate the other multiple rows in the table you are joining to.

    The easiest way to do this is to enhance your where clause or JOIN restriction to only join to the single record you would like. Usually this requires determining a rule which will always select the ‘correct’ entry from the other table.

    Let us assume you have a simple problem such as this:

    Person:  Jane
    Pets: Cat, Dog
    

    If you create a simple join here, you would receive two records for Jane:

    Jane|Cat
    Jane|Dog
    

    This is completely correct if the point of your view is to list all of the combinations of people and pets. However, if your view was instead supposed to list people with pets, or list people and display one of their pets, you hit the problem you have now. For this, you need a rule.

    SELECT Person.Name, Pets.Name
    FROM Person
      LEFT JOIN Pets pets1 ON pets1.PersonID = Person.ID
    WHERE 0 = (SELECT COUNT(pets2.ID) 
                 FROM Pets pets2
                 WHERE pets2.PersonID = pets1.PersonID
                    AND pets2.ID < pets1.ID);
    

    What this does is apply a rule to restrict the Pets record in the join to to the Pet with the lowest ID (first in the Pets table). The WHERE clause essentially says “where there are no pets belonging to the same person with a lower ID value).

    This would yield a one record result:

    Jane|Cat
    

    The rule you’ll need to apply to your view will depend on the data in the columns you have, and which of the ‘multiple’ records should be displayed in the column. However, that will wind up hiding some data, which may not be what you want. For example, the above rule hides the fact that Jane has a Dog. It makes it appear as if Jane only has a Cat, when this is not correct.

    You may need to rethink the contents of your view, and what you are trying to accomplish with your view, if you are starting to filter out valid data.

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

Sidebar

Ask A Question

Stats

  • Questions 163k
  • Answers 163k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do something similar by putting your controllers into… May 12, 2026 at 12:10 pm
  • Editorial Team
    Editorial Team added an answer I am not a lawyer, but I think that you… May 12, 2026 at 12:10 pm
  • Editorial Team
    Editorial Team added an answer A stack overflow happens not when your notation runs out… May 12, 2026 at 12:10 pm

Related Questions

We are working on a project that uses Flex and rails with WebORB .
I've worked with MySQL and MSSQL for some time and have used a variety
I'm working on an AJAXy project (Dojo and Rails, if the particulars matter). There
First off, I am fairly new to MVC and jQuery. I apologize if my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.