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.
| Author |
Topic |
|
Vatsan
Starting Member
7 Posts |
Posted - 2006-01-30 : 03:20:30
|
| VERY URGENT!!!There is a table with the following columnsnetwork_group_id | segment_id | age_key | gender_key | count |--------------------------------------------------------------- 0 1 1 1 10 0 2 1 2 12 1 1 2 2 20and so on...Now i have to find the segment_id, age_key, gender_key combination that is in network_group_id = 0 and not in network_group_id = 1and vice versa... and insert the same with zero as dummy values...Is there any operator to perform an intersect/minus kind of function.Please excuse me if this looks kiddish to u experts... but i need a solution ASAP... |
|
|
elwoos
Master Smack Fu Yak Hacker
2052 Posts |
Posted - 2006-01-30 : 03:28:12
|
| Hello Vatsan, welcome to SQL Team. If you give an example of the resutlts you expect I'm sure someone will be able to helpsteve-----------Facts are meaningless. You could use facts to prove anything that's even remotely true! |
 |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2006-01-30 : 03:32:44
|
| see if this helps..to fetch records which exist for group_id 0 and not in 1select network_group_id,0,0,0,0 from table where segment_id+age_key+gender_key not in (select segment_id+age_key+gender_key from table where network_group_id =1)where network_group_id =0 |
 |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2006-01-30 : 03:44:30
|
| oops..there was an errortry this..select * from [tablename] where cast(segment_id as varchar)+ cast(age_key as varchar)+cast( gender_key as varchar)not in (select cast(segment_id as varchar)+ cast (age_key as varchar)+cast(gender_key as varchar) from [tablename] where network_group_id =1)and network_group_id = 0 |
 |
|
|
Vatsan
Starting Member
7 Posts |
Posted - 2006-01-30 : 06:14:55
|
| Thanks Guys...Hi gupta,It was gr8... u made it work... hats off 2 u...I tried a diff method... please look into the query i used & tell me y i should not use this. The query u sent runs a bit faster. but when i view the execution plan... it takes a lot more steps & cost than what i have below... It would be gr8 if u cld explain me when & where shld i use a join.Thanks 4 u help guys... The code is working fine...select network_group_id, segment_id, age_key, gender_key, 0,0,0,0,0,0,0,0,0,0,0,0 from (select network_group_id,segment_id,age_key,gender_key,T1.segment_id as seg_id from(select distinct network_group_id,segment_id,age_key,gender_key from seg_normswhere network_group_id = 1)T0 left outer join(select distinct network_group_id,segment_id,age_key,gender_key from seg_normswhere network_group_id = 0)T1on T0.segment_id = T1.segment_idand T0.age_key = T1.age_keyand T0.gender_key = T1.gender_key )T2where T2.seg_id is null |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|