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

  • Home
  • SEARCH
  • 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 3222612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:00:40+00:00 2026-05-17T16:00:40+00:00

I am doing a inner join between two tables where one is an association

  • 0

I am doing a inner join between two tables where one is an association table, so there is a many to one relationship. I am trying to come up with a query that can decide if the key on the join exist more than once than store a value multiple in the update column, but not sure the efficient way to make this happen:

SELECT 
  MainTable.Name 
FROM MainTable 
INNER JOIN ASSN_Main ON MainTable.AppID = ASSN_Main.AppID 
WHERE 
  EXISTS (SELECT 
            COUNT(MainTable.AppID) 
          FROM MainTable 
          INNER JOIN ASSN_Main ON MainTable.AppID = ASSN_Main.AppID 
          GROUP BY 
            MainTable.AppID 
          HAVING 
            (COUNT(MainTable.AppID)>1));

The problem is the subquery grabs the correct ones that have duplicates on the appid, but the main SELECT query grabs all appid names instead of only the ones that exist in the subquery. Not sure whats going wrong since the subquery is correct?

  • 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-17T16:00:40+00:00Added an answer on May 17, 2026 at 4:00 pm

    There is no relation between the items in the main query and the items in the subquery, so what the query is returning is “all items, if there are any items that have duplicates”. What you want is “all items where there are duplicates”:

    SELECT 
      MainTable.Name 
    FROM MainTable m
    INNER JOIN ASSN_Main a ON m.AppID = a.AppID 
    WHERE 
      EXISTS (SELECT AppID
              FROM ASSN_Main
              WHERE AppID = m.AppID
              GROUP BY AppID 
              HAVING COUNT(*)>1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relationship between two tables. The two tables PKs are int types.
Is there any difference between these two LINQ statements: var query = from a
I'm trying to find number of rows for two tables: Example 1 returns 81
When doing an INSERT with a lot of data, ie: INSERT INTO table (mediumtext_field)
I doing a function in Javascript like the VisualBasic DateDiff. You give two dates
When doing an ALTER TABLE statement in MySQL, the whole table is read-locked (allowing
I have two tables: TableA ( ID [int, pk], Name [string]) and TableB (ID
I have two ( characteristic_list and measure_list ) tables that are related to each
I'm using Entity Framework 4 and having trouble with a query. I have two
There are 2 tables: report (which has a primary key of reportId and a

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.