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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:04:17+00:00 2026-05-23T06:04:17+00:00

I have two tables : TableA TableB id id amt amt idUser idTableA Let’s

  • 0

I have two tables :

TableA        TableB
id            id
amt           amt
idUser        idTableA

Let’s say the following data is in TableA :

1   10  1
2   20  1
3   30  1
4   40  2
5   50  3
6   60  4
7   70  4

and the following data is in TableB :

1   10  1
2   20  2
3   21  2
4   51  5
5   70  7

All fields are not nullable.

if I want to know what items in TableA have no ‘link’ to tableB (through the TableB.idTableA field), I can do this query :

SELECT a.id, a.amt
FROM TableA a LEFT JOIN TableB b on b.idTableA = a.id
WHERE b.idTableA IS NULL

and it will return the following :

3   30
4   40
6   60

if I want to know what items in TableA (that do have a link to tableB) for which the amt values are not identical in each table I can do :

SELECT a.id, a.amt, b.amt
FROM TableA a INNER JOIN TableB b on b.idTableA = a.id
WHERE a.amt <> b.amt

and it will return :

2   20  21
5   50  51

Now, I would like a query that does the following :
Return the idUsers for which only some of their entries in TableA have a link with TableB (meaning that for the idUser, there must also be some entries in the TableA with no link between the two tables) and for which at least one entry has different amounts between the two tables among the lines that are linked.

In my example, the idUser 1 would be returned by such a query because the third entry in TableA fulfills the first condition (some entries with no link) and there exists an entry for which amounts are different (linked with the value 2 for idTableA are amounts 20 in TableA vs 21 in TableB)

userId 2 will not be returned because it has no line linked between the two tables,

userId 3 will not be returned because it does not have a line in TableA without link in TableB

userId 4 will not be returned because although it has 1 line in TableA without link and also 1 line with a link, the line with a link has its amounts identical between the 2 tables.

So really it is a mix of the two initial queries…

Thanks for your input and my apologies for the basic formatting and language, I hope this is clear enough 🙂

  • 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-23T06:04:18+00:00Added an answer on May 23, 2026 at 6:04 am
    with loners as (
    SELECT a.*
    FROM TableA a 
    LEFT JOIN TableB b on b.idTableA = a.id
    WHERE b.idTableA IS NULL
    ), 
    diffs as (
    SELECT a.*
    FROM TableA a 
    INNER JOIN TableB b on b.idTableA = a.id
    WHERE a.amt <> b.amt
    )
    select loners.userID
    FROM loners
    INNER JOIN diffs on LONERS.userID = DIFFS.userID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: Let's say I have two tables, TableA and TableB. TableB's primary key is
I have two tables called TableA and TableB. TableA has the following fields: TableA_ID
I have two tables: TableA ( ID [int, pk], Name [string]) and TableB (ID
I have two tables TableA aId aValue TableB bId aId bValue I want to
I have two mysql tables: TableA has 10,000 records TableB has 2,000 records. I
I have two tables, both with start time and end time fields. I need
I have two tables with the following schema: CREATE TABLE sales_data ( sales_time date
in mysql i have two tables tableA col1 col2 SIM1 ..........col24 ----------------------------------- a x
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and

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.