Home > OS >  Show items not in table
Show items not in table

Time:01-06

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?

CodePudding user response:

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';

CodePudding user response:

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'

CodePudding user response:

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')
  • Related