|
The First image is my main table "Master"..and the second one is another table "Item" I the Serno in the master is the Foreign key(Items) in the Item
(comments are locked)
|
|
-- Method 1 Select * From Menu_Master where serno not in (select items from order_items where order_id = 38) -- Method 2 select a.serno, a.cat, a.item, a.cost, a.datetime from menu_master a left outer join order_items as b on a.serno = b.items and b.order_id = 38 where b.items is null
(comments are locked)
|
|
If you pass it the Order_ID as 38, from the data you show, SQL Server can only return semo 7 and 9 because those are the only values where the Order_Id matches. Not seeing the complete structure, it's hard to say more. Maybe you're looking for an OUTER JOIN to retrieve all data from one table, and only the matching data from the other. In this case, just make sure that the filtering criteria is in the ON clause, not the WHERE clause. Thank you sir for the reply..But that's my issue ..how do i get the columns which have not being used along with the where condition .. because there are loads of order-Id like 38 ,39 ,40
Jul 31 '12 at 10:45 AM
fashraf
I guess I don't understand. If you filter for a particular condition, Order_Id = 38, then you should only expect to see rows that match that condition returned. That's the idea behind applying a filter. If you want to see all data returned, then you can't apply a condition like that.
Jul 31 '12 at 11:24 AM
Grant Fritchey ♦♦
Method 2 should work better generally and is easier to understand.
Jul 31 '12 at 11:43 AM
Grant Fritchey ♦♦
(comments are locked)
|

