budhimantudu Posted July 8, 2015 Report Posted July 8, 2015 Sql heros.... I have two tables like below.... Now i want the id which matches both tables i.e ID 2.. I am running joins but no use... i am getting both id's... Can anyone help... ? i need an generic sollution... not specific as the real data has many columns... P.S : anni values compare cheiali... mottam data analyse chesi 2 tables lo match aina data id value kavali...
ibabu Posted July 8, 2015 Report Posted July 8, 2015 Sql heros.... I have two tables like below.... Now i want the id which matches both tables i.e ID 2.. I am running joins but no use... i am getting both id's... Can anyone help... ?Select b.id From A,b where a.id=b.id You can add select distinct b.id to get distinct id's
budhimantudu Posted July 8, 2015 Author Report Posted July 8, 2015 Select b.id From A,b where a.id=b.id You can add select distinct b.id to get distinct id's appudu rendu id's vastunai bro... P.S : anni values compare cheiali... mottam data analyse chesi 2 tables lo match aina data id value kavali...
ibabu Posted July 8, 2015 Report Posted July 8, 2015 appudu rendu id's vastunai bro... P.S : anni values compare cheiali... mottam data analyse chesi 2 tables lo match aina data id value kavali... Output ela kavali? B.id ante only 2nd. Table id vastindi ? Naaku nee requirement ardham kavatltle.. If you want to compare Ids in next level select case when id1=id2 then aa end from ( select * from a,b full outer join)
budhimantudu Posted July 8, 2015 Author Report Posted July 8, 2015 Output ela kavali? B.id ante only 2nd. Table id vastindi ? Naaku nee requirement ardham kavatltle.. If you want to compare Ids in next level select case when id1=id2 then aa end from ( select * from a,b full outer join) 2 tables lo data vundi with diff id's konni id's ki oka table lo null values vunnai and other table has some value for same row and konni id's ki exact matches vunnai for same row... naku exact ga match aina rows id kavali.... there are many columns so generic solution emaina vunda... ?
ibabu Posted July 8, 2015 Report Posted July 8, 2015 2 tables lo data vundi with diff id's konni id's ki oka table lo null values vunnai and other table has some value for same row and konni id's ki exact matches vunnai for same row... naku exact ga match aina rows id kavali.... there are many columns so generic solution emaina vunda... ? Select a1||a2||a3 from a Intersect Select b1||b2||b3 from b
parabramha Posted July 8, 2015 Report Posted July 8, 2015 Table 1 and Table 2 oo enni rows unnayi ? do a left join between full outer join between two tables.. Case statement rayi.. if both of them matches then 'true' else false . Then select the values where min(value) of col1 = 'true' and min(value) of col2 true ='true' select distinct a.id from (select coalesce(t1.id,t2.id,9999) id , case when coalesce(t1.col1,-9)=coalesce(t2.col1,-9) then 'true' else 'false' end col1_flag, case when coalesce(t1.col2,-9)=coalesce(t2.col2,-9) then 'true' else 'false' end col2_flag, from table1 t1 full outer join table2 t2 on (t1.id=t2.id))a group by a.id having min(col1_flag)='true' and min(col2_flag)='true';
Recommended Posts