Joing two tables showing me records from one tables where it doesn't have a corresponding value in another table

BobSki

So I have two tables that I'm trying to do a join on showing me records in one table that don't have corresponding values in another table....

tbl1

ClientNo      DateRec       CompID
123           1/2/2017      5558
124           1/3/2017      5558
234           1/3/2017      5558


tbl2
ClientNO      CompID
123           5558
124           5558

So eveerything here is based on CompID = 5558. This is the magic number. I'm looking to join both tables and only show me records from tbl1 - where tbl2 does not have a record for the same clientID and 5558.

Desired end result:

 ClientNo      DateRec       CompID
 234           1/3/2017      5558

This is my desired end result because client 234 does not have the same CompID in tbl2. So my goes is only show me records from tbl1 where tbl2 doesn't have the same CompID (in this case 5558)

Gordon Linoff

You have pretty much described not exists:

select t.*
from tbl1 t
where not exists (select 1 from tbl2 t2 where t2.ClientNo = t.ClientNo and t2.CompId = t.CompId);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

join two tables in one with one id and multiple ids in another table

From Dev

output two tables from one input table in lua first output table will have all keys and second will have all values of input table

From Dev

Creating SQL Query involving two tables where one table is required only for a single value

From Dev

Hibernate: How to join two tables with one of it doesn't have an id?

From Dev

Comparing two tables where one column matches and the other doesn't

From Dev

Find records from a table that, among associated records in another table, don't have a record with a specific field value

From Dev

Displaying value from one table that doesn't have an id number in another

From Dev

How do a join three tables where one table doesn't match the ID of the other two?

From Dev

How to avoid the duplicate value while joing two tables?

From Dev

Creating a view with two tables, where second table doesn't have unique IDs

From Dev

CakePHP joing two tables

From Dev

Insert two records at once into two tables where one table uses the other as foreign key?

From Dev

updating one table with the value of another table and the two tables are in seperate database

From Dev

LINQ Query To Join Two Tables and Select Most Recent Records from Table B corresponding to Table A

From Dev

How to get records from two tables with multiple where conditions

From Dev

How to get all records from two tables where doesn't exists in third

From Dev

Getting the value from one table with inputs of two different tables

From Dev

join two tables in one with one id and multiple ids in another table

From Dev

Selecting one record from two tables and multiple records from another table in ONE query

From Dev

how do I join multiple tables if one table doesn't have the reference?

From Dev

Displaying value from one table that doesn't have an id number in another

From Dev

joing two tables with count values

From Dev

How to return data from two tables only when the column value in one table is same as another table using MySQL?

From Dev

SQL across two tables is showing duplicate records

From Dev

Efficiency of tables that have a mapping to another table where their real value is held in MySQL

From Dev

Between two tables how does one SELECT the table where the id of a specific value exists mysql (duplicate)

From Dev

Insert records from two different tables into one

From Dev

How can I select from items from two tables with one item only have one value

From Dev

SQL INSERT INTO two tables from one table

Related Related

  1. 1

    join two tables in one with one id and multiple ids in another table

  2. 2

    output two tables from one input table in lua first output table will have all keys and second will have all values of input table

  3. 3

    Creating SQL Query involving two tables where one table is required only for a single value

  4. 4

    Hibernate: How to join two tables with one of it doesn't have an id?

  5. 5

    Comparing two tables where one column matches and the other doesn't

  6. 6

    Find records from a table that, among associated records in another table, don't have a record with a specific field value

  7. 7

    Displaying value from one table that doesn't have an id number in another

  8. 8

    How do a join three tables where one table doesn't match the ID of the other two?

  9. 9

    How to avoid the duplicate value while joing two tables?

  10. 10

    Creating a view with two tables, where second table doesn't have unique IDs

  11. 11

    CakePHP joing two tables

  12. 12

    Insert two records at once into two tables where one table uses the other as foreign key?

  13. 13

    updating one table with the value of another table and the two tables are in seperate database

  14. 14

    LINQ Query To Join Two Tables and Select Most Recent Records from Table B corresponding to Table A

  15. 15

    How to get records from two tables with multiple where conditions

  16. 16

    How to get all records from two tables where doesn't exists in third

  17. 17

    Getting the value from one table with inputs of two different tables

  18. 18

    join two tables in one with one id and multiple ids in another table

  19. 19

    Selecting one record from two tables and multiple records from another table in ONE query

  20. 20

    how do I join multiple tables if one table doesn't have the reference?

  21. 21

    Displaying value from one table that doesn't have an id number in another

  22. 22

    joing two tables with count values

  23. 23

    How to return data from two tables only when the column value in one table is same as another table using MySQL?

  24. 24

    SQL across two tables is showing duplicate records

  25. 25

    Efficiency of tables that have a mapping to another table where their real value is held in MySQL

  26. 26

    Between two tables how does one SELECT the table where the id of a specific value exists mysql (duplicate)

  27. 27

    Insert records from two different tables into one

  28. 28

    How can I select from items from two tables with one item only have one value

  29. 29

    SQL INSERT INTO two tables from one table

HotTag

Archive