Subtract rows from a table, using subquery which may be empty

Kaya Toast
table: A
-----------
value
1
2
3

sub-query: B
-----------
value
2

I need (A - B).

The below query works when B is not empty. Output = (1,3) as expected.

SELECT * FROM A
JOIN B
ON (A.value != B.value)

However, when the sub-query B is empty, the JOIN does an intersection of A with an empty B, and the output is an empty result-set.

And if I use LEFT JOIN, it does not subtract the row containing value 2 from table A.

Is it possible to write a single query for (A - B), irrespective of whether B is empty or not.

Alex
SELECT A.* 
FROM A
LEFT JOIN B
ON A.value = B.value
WHERE b.value IS NULL

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

is it possible to use a subquery instead of a table in from clause using access?

From Dev

Subtract rows of one table from another table

From Dev

Adding constraints using subquery from other table

From Dev

Insert multiple rows from other table - "Subquery returns more than 1 row"

From Dev

print complete rows in table which is passed from servlet

From Dev

Subtract even rows from odd rows using awk, etc

From Dev

The Subquery which returns multiple rows in Oracle SQL

From Dev

How to subtract inventory and sale using mysql subquery?

From Dev

How to delete all rows from table which has no FK relation

From Dev

Append empty table rows to a table

From Dev

INSERT using SELECT from potentially empty table

From Dev

Why are my table columns not recognized when using a FROM subquery in Oracle?

From Dev

Fetch rows in MySQL which are not present in both columns from another table

From Dev

How to read a table from an Excel document that has empty rows using Laravel

From Dev

(SQLITE) How to add together sums from another table using a subquery

From Dev

How to get the name of the table from which rows where found

From Dev

Subtract one table from another

From Dev

Insert (multiple) new rows into a table from another table using a subquery?

From Dev

Add a (second) condition to delete empty rows from a table

From Dev

How to subtract rows from first row using awk?

From Dev

No rows returned from a non-empty table

From Dev

Using subquery in FROM for HQL

From Dev

Delete lines from input files excluding patterns listed in another file which may be empty in some cases?

From Dev

Fetch rows in MySQL which are not present in both columns from another table

From Dev

Removing empty rows from Table jQuery

From Dev

Subtract row from all rows with same identifier using R

From Dev

SQL Rows are not deleted from table when using where not exists and select distinct subquery

From Dev

Return multiple rows from subquery

From Dev

Subquery from the same table

Related Related

  1. 1

    is it possible to use a subquery instead of a table in from clause using access?

  2. 2

    Subtract rows of one table from another table

  3. 3

    Adding constraints using subquery from other table

  4. 4

    Insert multiple rows from other table - "Subquery returns more than 1 row"

  5. 5

    print complete rows in table which is passed from servlet

  6. 6

    Subtract even rows from odd rows using awk, etc

  7. 7

    The Subquery which returns multiple rows in Oracle SQL

  8. 8

    How to subtract inventory and sale using mysql subquery?

  9. 9

    How to delete all rows from table which has no FK relation

  10. 10

    Append empty table rows to a table

  11. 11

    INSERT using SELECT from potentially empty table

  12. 12

    Why are my table columns not recognized when using a FROM subquery in Oracle?

  13. 13

    Fetch rows in MySQL which are not present in both columns from another table

  14. 14

    How to read a table from an Excel document that has empty rows using Laravel

  15. 15

    (SQLITE) How to add together sums from another table using a subquery

  16. 16

    How to get the name of the table from which rows where found

  17. 17

    Subtract one table from another

  18. 18

    Insert (multiple) new rows into a table from another table using a subquery?

  19. 19

    Add a (second) condition to delete empty rows from a table

  20. 20

    How to subtract rows from first row using awk?

  21. 21

    No rows returned from a non-empty table

  22. 22

    Using subquery in FROM for HQL

  23. 23

    Delete lines from input files excluding patterns listed in another file which may be empty in some cases?

  24. 24

    Fetch rows in MySQL which are not present in both columns from another table

  25. 25

    Removing empty rows from Table jQuery

  26. 26

    Subtract row from all rows with same identifier using R

  27. 27

    SQL Rows are not deleted from table when using where not exists and select distinct subquery

  28. 28

    Return multiple rows from subquery

  29. 29

    Subquery from the same table

HotTag

Archive