Jump to content
Jim S-T

Exists operator

Recommended Posts


I am slowly making my way through the SQL tutorial and have got a bit stuck on the exists tutorials. This is one of the examples, but I do not understand why they have used SELECT ProductName.

SELECT supplierid, SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE SupplierId = Suppliers.supplierId AND Price < 20);


When running SQL it provides 2 columns, supplier ID and Supplier Name as per the 1st line. I have replaced ProductName with * and get the same results, is it a best practice thing, or have I been getting worked up over not much as they just needed something to fill the space?








Share this post

Link to post
Share on other sites

Which columns are selected inside the exists subquery is totally irrelevant, they aren't even used.  I always do SELECT * for those.  The only thing that matters is if a row was returned at all, the number or values of columns aren't even considered.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...