Jim S-T Posted March 13, 2019 Share Posted March 13, 2019 Hi, 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? Thanks Jim Link to comment Share on other sites More sharing options...
justsomeguy Posted March 13, 2019 Share Posted March 13, 2019 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. Link to comment Share on other sites More sharing options...
Jim S-T Posted March 17, 2019 Author Share Posted March 17, 2019 Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now