How do SQL EXISTS statements work?

前端 未结 7 510
不知归路
不知归路 2020-12-04 05:20

I\'m trying to learn SQL and am having a hard time understanding EXISTS statements. I came across this quote about \"exists\" and don\'t understand something:

7条回答
  •  一个人的身影
    2020-12-04 05:53

    If you had a where clause that looked like this:

    WHERE id in (25,26,27) -- and so on
    

    you can easily understand why some rows are returned and some are not.

    When the where clause is like this:

    WHERE EXISTS (select * from orders where suppliers.supplier_id = orders.supplier_id);
    

    it just means : return rows that have an existing record in the orders table with te same id.

提交回复
热议问题