MySQL - How to get a list of values in Table A that don't exist in Table B?

后端 未结 3 480
借酒劲吻你
借酒劲吻你 2021-01-26 07:51
**Table A**
1
2
3
4
5
6


**Table B**
2
3
5

How can I select for entry IDs that only exist in Table B? In this example, I\'m looking for a query th

3条回答
  •  悲哀的现实
    2021-01-26 08:36

    This avoids IN + subquery:

    SELECT A.value FROM A
    LEFT OUTER JOIN B ON (A.value = B.value)
    WHERE B.value IS NULL
    

    Because IN (subquery) isn't optimized as it is executed for each found row in table A

提交回复
热议问题