You can try this...create table t6(id int,fname varchar(40),lname varchar(40),age int,sex char(1),income int)insert into t6 values (1,'ram','shah',25,'M',20000)insert into t6 values (2,'rahim','shukla',35,'M',10000)insert into t6 values (3,'viral','desai',23,'M',20000)insert into t6 values (4,'tara','jaiswal',26,'F',25000)insert into t6 values (5,'manu','shah',22,'M',10000)insert into t6 values (6,'viral','shah',26,'M',20000)insert into t6 values (7,'ram','shah',23,'M',20000)insert into t6 values (8,'sumi','shah',25,'F',20000)insert into t6 values (9,'imli','patel',27,'M',25000)insert into t6 values (10,'imli','patel',27,'F',25000) select id,fname,lname,sex,age,income, case when fname=(select fname from t6 where id=1) then 1 else 0 end + case when lname=(select lname from t6 where id=1) then 1 else 0 end + case when age=(select age from t6 where id=1) then 1 else 0 end + case when sex=(select sex from t6 where id=1) then 1 else 0 end + case when income=(select income from t6 where id=1) then 1 else 0 end Matchfrom t6where ( fname like (select fname from t6 where id=1) or lname like (select lname from t6 where id=1) or age=(select age from t6 where id=1) or sex=(select sex from t6 where id=1) or income=(select income from t6 where id=1) ) and id!=1order by id