Author |
Topic |
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2010-07-20 : 18:19:24
|
Hi,I have a situation,Tables:Iteminfo-- Itemnum-- OrgidOrginfo-- OrgidOrginfo is a master table it is having 6 organizations. The requirement is each item in the iteminfo table should have 6 organizations which is should be in the orginfo table. I have some of the items are missing some of the organizations in iteminfo table. I want to find out the missing organizations for each item.Could anyone please suggest me to achive this requirement.Thanks in advance-- Krishna |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2010-07-20 : 18:22:21
|
Thanks for the reply.6 are different organizations |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2010-07-20 : 18:31:02
|
No it can not be more than 6. Because we have only 6 organizations. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2010-07-20 : 18:47:20
|
Sure, that will give the clear picture. I am sorry about that.IteminfoItemnum orgid1000 AFc1000 ASc1000 SBC1003 AFC1003 ASC1003 SBC1003 FFC1003 GFC1003 NSC1004 AFC1005 AFC1005 ASC1005 SBC1005 FFC1005 GFC1006 SBC1006 FFC1006 GFCORGinfoOrgidAFCASCSBCFFCGFCNSCIn the above data, item 1003 is having 6 organization. but rest of the items are missing some organizations.For example item 1000 ismissing ffc, gfc and NSC. I want to find the missing org for each item in that table. Hope i am clear now. Please let me know if i did not explain you clearly. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2010-07-20 : 18:54:16
|
Thanks. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-07-20 : 21:55:45
|
[code]select *from ( select distinct Itemnum from Iteminfo i ) a -- replace with Item table if you have one cross join ORGinfo b left join Iteminfo i on a.Itemnum = i.Itemnum and b.Orgid = i.Orgidwhere i.Itemnum is nullORselect *from ( select distinct Itemnum from Iteminfo i ) a cross join ORGinfo bwhere not exists ( select * from Iteminfo x where x.Itemnum = a.Itemnum and x.Orgid = b.Orgid )[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2010-07-20 : 22:30:55
|
Khtan, both of your SQL worked fine. Awesome !!!. This trick didn't raise on my brain. Thank you very much. Thank you Tara. |
|
|
|