How do I select all id's that are present in one table but not in another

Cache Staheli

I am trying to get a list of department Ids are present in one table, (PS_Y_FORM_HIRE), but which don't exist in another table (PS_DEPARTMENT_VW).

Here is the basics of what I have which isn't working:

SELECT h.DEPTID FROM PS_Y_FORM_HIRE h, PS_DEPARTMENT_VW d WHERE NOT EXISTS (
    SELECT d1.DEPTID FROM PS_DEPARTMENT_VW d1 WHERE d1.DEPTID = h.DEPTID 
        and d1.SETID_GL_DEPT = 'IDBYU'
);

I'm trying to form this query in SQL Developer, but it just returns a long list of blanks (after spinning/running the query for a very long time).

In addition, I need this to be effective dated, so that it only grabs the correct effective-dated row, but I was unsure how and where to incorporate this into the query.

EDIT I neglected to mention that only the department table is effective dated. The form hire table is not. I need to get the current effectively dated row from that in this query (to make sure the data is accurate).

Also note that DEPTID isn't a key on PS_Y_FORM_HIRE, but is on PS_DEPARTMENT_VW. (Along with SETID_GL_DEPT and EFFDT).

So again, ideally, I will have a list of all the department ids that appear in PS_Y_FORM_HIRE, but which are not in PS_DEPARTMENT_VW.

MT0
SELECT DEPTID
FROM   PS_Y_FORM_HIRE
MINUS
SELECT DEPTID
FROM   PS_DEPARTMENT_VW
WHERE  SETID_GL_DEPT = 'IDBYU';

or

SELECT DEPTID
FROM   PS_Y_FORM_HIRE
WHERE  DEPTID NOT IN (
  SELECT DEPTID
  FROM   PS_DEPARTMENT_VW
  WHERE  SETID_GL_DEPT = 'IDBYU'
)

or

SELECT DEPTID
FROM   PS_Y_FORM_HIRE h
WHERE  NOT EXISTS (
  SELECT 1
  FROM   PS_DEPARTMENT_VW d
  WHERE  SETID_GL_DEPT = 'IDBYU'
  AND    d.DEPTID = h.DEPTID
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I get all values present in one table, but only some from another table

From Dev

Select all records from table A, even if one or more of it's ID(i.e FK) not present in table B

From Dev

How to select all records from one table that do not exist in another table for certain condition in another table?

From Dev

Selenium IDE / Xpath - How do I select an element inside a table cell when another given element is NOT present?

From Dev

How do I make select option of only one select field display another div when multiple select fields are present

From Dev

How to select all records from one table that do not exist in another table but return NULL in the record that do not exist

From Dev

How do I select items from one table such that a query in another table yields exactly one row?

From Dev

How do I select items from one table such that a query in another table yields exactly one row?

From Java

How to select all records from one table that do not exist in another table?

From Dev

How do I select rows from a table if I know value in another table but not ID?

From Dev

SELECT all when ID is not in another table in one query

From Dev

How to select values which are not present in another table?

From Dev

how would i get it to show me records in one table that arent present in another table using an EQUI JOIN?

From Dev

SQL Procedure to return all values of one table and YES/NO if present in another

From Dev

How do I merge one SQL 2005 Table with another Table?

From Dev

How do i copy data from one table to another table?

From Dev

How do i copy data from one table to another table?

From Dev

How do I select rows which do not exists in another table

From Dev

How do I select rows which do not exists in another table

From Dev

How do I select a given number of rows for one table for each parent primary key in another table in sql server 2012?

From Dev

How to select all even id's from a Table?

From Dev

How to get all columns from one table and only one column from another table with ID ? - MySql

From Dev

How do I present a ViewController over another with that VC having no knowledge of the new one?

From Dev

How do I remove all the lines in a text file that are present in another text file in Windows?

From Dev

How do I find all the lines that are in one file and not in another?

From Dev

In standard SQL, how do I select rows such that for each unique value in one column, all of the values in another column are a specified value?

From Dev

In standard SQL, how do I select rows such that for each unique value in one column, all of the values in another column are a specified value?

From Dev

Maya, PYTHON: how do i select all but one in a list?

From Dev

How do I query for a set of all unique values present in my table?

Related Related

  1. 1

    How do I get all values present in one table, but only some from another table

  2. 2

    Select all records from table A, even if one or more of it's ID(i.e FK) not present in table B

  3. 3

    How to select all records from one table that do not exist in another table for certain condition in another table?

  4. 4

    Selenium IDE / Xpath - How do I select an element inside a table cell when another given element is NOT present?

  5. 5

    How do I make select option of only one select field display another div when multiple select fields are present

  6. 6

    How to select all records from one table that do not exist in another table but return NULL in the record that do not exist

  7. 7

    How do I select items from one table such that a query in another table yields exactly one row?

  8. 8

    How do I select items from one table such that a query in another table yields exactly one row?

  9. 9

    How to select all records from one table that do not exist in another table?

  10. 10

    How do I select rows from a table if I know value in another table but not ID?

  11. 11

    SELECT all when ID is not in another table in one query

  12. 12

    How to select values which are not present in another table?

  13. 13

    how would i get it to show me records in one table that arent present in another table using an EQUI JOIN?

  14. 14

    SQL Procedure to return all values of one table and YES/NO if present in another

  15. 15

    How do I merge one SQL 2005 Table with another Table?

  16. 16

    How do i copy data from one table to another table?

  17. 17

    How do i copy data from one table to another table?

  18. 18

    How do I select rows which do not exists in another table

  19. 19

    How do I select rows which do not exists in another table

  20. 20

    How do I select a given number of rows for one table for each parent primary key in another table in sql server 2012?

  21. 21

    How to select all even id's from a Table?

  22. 22

    How to get all columns from one table and only one column from another table with ID ? - MySql

  23. 23

    How do I present a ViewController over another with that VC having no knowledge of the new one?

  24. 24

    How do I remove all the lines in a text file that are present in another text file in Windows?

  25. 25

    How do I find all the lines that are in one file and not in another?

  26. 26

    In standard SQL, how do I select rows such that for each unique value in one column, all of the values in another column are a specified value?

  27. 27

    In standard SQL, how do I select rows such that for each unique value in one column, all of the values in another column are a specified value?

  28. 28

    Maya, PYTHON: how do i select all but one in a list?

  29. 29

    How do I query for a set of all unique values present in my table?

HotTag

Archive