Jump to content

Simple Sql Query.. I Am Missing Something Very Obvious


Recommended Posts

Posted
I have two tables.. I need second table record to be eliminated from first.. I am very something very obvious.. please help me bhaiya
 
 
TABLE 1
column_1  column_2
Rajesh      BENZ
Rajesh      TOYOTA
Suresh      BMW
Mahesh      Nissan 
Mahesh      GM      
Anirvesh    AUDI
Anvesh      MAZDA
 
 
TABLE 2
column_1  column_2
Rajesh      BENZ
Suresh      BMW
Mahesh      GM      
Anirvesh    AUDI
Parvesh     HONDA
 
I NEED OUTPUT TABLE TO LOOK LIKE
 
OUTPUT TABLE
column_1  column_2
Rajesh      TOYOTA
Mahesh      Nissan 
Anvesh      MAZDA
 
 
 
 
Posted

Union all 2 tables.. then group by two columns having count(*)<2

Posted

Exists condition try cheyyi... .///

 

 

NOT EXISTS uh bhaiya.... R u sure.?

Posted

Union all 2 tables.. then group by two columns having count(*)<2 ..//

 

Second table lo records naku vadhu bhaiya.... i need first table with records which are not as same as in  second table

Posted

select * from t1, t2 where t1.col1=t2.col1 and t1.col2 <> t2.col2

Posted

select * from table1 

minus

select * from table2

Posted

select * from t1, t2 where t1.col1=t2.col1 and t1.col2 <> t2.col2 ..///

 

 

i will miss record which is in first.. not in second... 

Posted

select * from t1, t2 where t1.col1=t2.col1 and t1.col2 <> t2.col2 ..///


i will miss record which is in first.. not in second...

ooh ok, then minus use cheye paina cheppinattu or else not exists use cheye
Posted

select * from table1 

minus

select * from table2

 

It should Work. Otherwise You can try with Left Outer Join and sub query like below.

 

SELECT

     COL1,

     COL2

FROM

(  SELECT

        A.COL1,

        A.COL2,

        B.FLAG

    FROM TABLE1 A

    LEFT OUTER JOIN TABLEB B

         ON B.COL1=A.COL1 AND A.COL2=B.COL2

)

WHERE FALG IS NULL;

Posted

Just use Except operator man

 

SELECT col1 , col2 FROM TABLEA
EXCEPT
SELECT col1, Col2 FROM TABLEB
Posted

SELECT distinct cols FROM A
union
SELECT distinct cols FROM B

Posted
select t1.* from t1 
left join t2 on t1.col2 = t2.col2
 
where t2.col1 is null
 
 
test kuda chesina.. work chestundi chudu.. pakka.
Posted

Select * from table1 t1 where not exists (select * from table2 t2 where t1.column1 = t2.column_1 and t1.column2 = t2.column_2)

×
×
  • Create New...