skip to Main Content

I am trying to return a list of brands that do not have a specific product ID.

Using the following SQL:

SELECT Brands
FROM AllCustomers
WHERE ProductID NOT IN (SELECT ProductID WHERE ProductID ='10235')

Is there a more effective way to do this as it keeps timing out?

3

Answers


  1. Given your subquery has the explicit ProductID in the where clause and the subquery is only returning the ProductID you could simplify your query to be

    SELECT Brands FROM AllCustomers WHERE ProductID <> '10235';
    
    Login or Signup to reply.
  2. If you already have product ID, then why are you adding sub query ?

    Simply write down query like:

    SELECT `Brands` FROM `AllCustomers` WHERE `ProductID`!='10235'
    
    Login or Signup to reply.
  3. Assuming you will actually use the same syntax for other queries, you didn’t specify a table in your sub-query.
    Eg, if we are getting the filtered records of ProductID from the same table, it should be:

    SELECT Brands FROM AllCustomers WHERE ProductID NOT IN (SELECT ProductID FROM AllCustomers WHERE ProductID ='10235')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search