How to use Authorize Attribute in asp.net MVC?

SQL- How do I use the "IN" Attribute correctly?

  • I have a Query I need to make that shows all the products a company hasn't ordered. I figure I have to use an "IN" attribute, but I haven't wrapped my head around it yet. Here's what I have so far to make the products show. Any help is appreciated. and if more info is needed, let me know, I figured this bit of SQL I've come up with might be enough. SELECT Products.ProductID, Products.ProductName, Customers.CompanyName FROM Customers, Products, Orders, [Order Details] WHERE Customers.CustomerID = Orders.CustomerID AND Orders.OrderID=[Order Details].OrderID AND Products.ProductID =[Order Details].ProductID AND Customers.CompanyName = 'Bingo store' (SELECT ???? FROM ???? WHERE ????)

  • Answer:

    Well if you are trying to do a sub select, this is how you would do it: SELECT Products.ProductID, Products.ProductName, Customers.CompanyName FROM Customers, Products, Orders, [Order Details] WHERE Customers.CustomerID = Orders.CustomerID AND Orders.OrderID=[Order Details].OrderID AND Products.ProductID =[Order Details].ProductID AND Customers.CompanyName = 'Bingo store' And ProductID in (SELECT ProductID FROM Products WHERE ProductName='Toys')

swilliam... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

I would personally not use EXISTS, instead I would use NOT IN... SELECT Products.ProductID, Products.ProductName, Customers.CompanyName FROM Customers, Products, Orders, [Order Details] WHERE Customers.CustomerID = Orders.CustomerID AND Orders.OrderID=[Order Details].OrderID AND Products.ProductID =[Order Details].ProductID AND Customers.CompanyName = 'Bingo store' AND Products.ProductID NOT IN (SELECT DISTINCT t1.ProductID FROM Orders t1 WHERE t1.CompanyName = Customers.CompanyName)

The correct Where clause would be Where myColumnName in ('string1', 'string2', 'string3') So if myColumnName equals string1 or string2 or string3, that satisfies the condition. If you're looking to make the strings dynamic (like a variable), there's not a simple way to do that. In your case, I don't think IN is appropriate, and you should look into the EXISTS statement.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.