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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:24:04+00:00 2026-06-16T08:24:04+00:00

I have two tables, which share a column, that is not unique. I want

  • 0

I have two tables, which share a column, that is not unique. I want all records where table A has more values of the shared column than TABLE B.

TABLE A:
Shared_Column|User_ID|Department
123          |    joe|     sales
123          |    joe|     sales
123          |    joe|     sales
124          |    sam|       ops
124          |    sam|       ops

TABLE B
Shared_Column|Other_Column
123          |           1
123          |           1
124          |           4
124          |           4

From this data, I want joe|sales but not sam|ops. I could also work with this as output:

USER|TABLE_A_COUNT|TABLE_B_COUNT
 joe|            3|            2
 sam|            2|            2

edit: I’ve tried to do a join like this:

select a.user_ID, count(a.shared_column) as 'TABLE_A_COUNT', count(b.shared_column) as 'TABLE_B_COUNT'
from a inner join b on a.shared_column = b.shared_column
group by a.user_ID

but that seems to produce a cross join and I get joe|6|6 instead of 3 and 2

Thanks!

  • 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-06-16T08:24:08+00:00Added an answer on June 16, 2026 at 8:24 am

    It seems like you want something like this:

    select a.user_id,
      count(a.shared_column) TableA,
      TableB
    from tablea a
    inner join
    (
      select count(*) TableB, Shared_column
      from tableb
      group by shared_column
    ) b
      on a.Shared_Column = b.Shared_Column
    group by a.user_id, TableB
    

    See Sql Fiddle with Demo

    Result:

    | USER_ID | TABLEA | TABLEB |
    -----------------------------
    |     joe |      3 |      2 |
    |     sam |      2 |      2 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two or more tables which hold values under the same column name.
I have two tables which share common fields. Rather than re-map all of these
Hi I want to have two tables each have an INT id column which
I have two tables, Users and People, both of which share a common attribute,
I have two tables which looks something like this Table Queue int ID; string
I have two tables which I want to join together using a left outer
I have two tables Department Professor in which Department has an attribute called HeadID
I have two tables, each one has a primary ID column as key. I
I have two tables record and share . record has columns: name and id
I have two views that render a table on each. Most of the tables

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.