Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 problem with or in this query

Author  Topic 

veronika.np
Starting Member

29 Posts

Posted - 2011-06-24 : 12:00:14
hi friends,
i have a 3 tables.
item table with (id,name,itemcategoryid)
itemcategory with (id,name)
order(id,itemid,itemcategoryid)

i want to search for all items.in order table some rows have itemid and itemcategoryid is null.and some rows have itemcategoryid and itemid is null.i want to get all of item.(the items that are null by itemcategotyid exist)
i use from or but it hasen`t correct result.please help me.




select i.id from Item i join order o on
i.itemcategoryid = o.itemcategoryid
where ( (o.itemcategoryid is not null ) or( i.id in ( select i.id from order o
join Item i on i.id=o.itemid
where (0.itemid is not null) )))

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-06-24 : 14:16:12
I guess that an itemcategory can have many items.
So if an order has a value in column imtemcategoryid and null in itemid there is a big problem!
Or should this mean ALL items of the given categorie are in this order?

Looks very bad to me...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -