Complicated SQL Query--finding items matching multiple different foreign keys
问题 So imagine that you have a table of Products (ID int, Name nvarchar(200)) , and two other tables, ProductsCategories (ProductID int, CategoryID int) and InvoiceProducts (InvoiceID int, ProductID int) . I need to write a query to produce a set of products that match a given set of invoice ids and category ids such that the list of products match all the specified categories and all the specified invoices, without falling back to dynamic SQL. Imagine I need to find a list of products that are