Search This Blog

Monday, February 11, 2013

Sql query for Unique Output


SELECT * FROM userfORM

userid
usertype
name
branchid
username
1
1
chandra  
12
cp       
2
1
rp       
12
RP       
3
1
RAJ      
13
RAJ      
4
1
KAAL     
14
K        

 SELECT * FROM formA1

sno
userid
usertype
year
month
fileno
addno
computerno
person
1
1
1
2012     
9
234
345
3
4
2
3
1
2012     
9
2
4
5
56
3
1
1
2012     
8
3
3
3
3
4
4
1
2012     
8
2
3
34
3
6
3
1
2012     
8
34
34
56
555

 Select x.branchid from userfORM x inner join formA1 y on x.userid=y.userid where y.userid=x.userid and  y.year='2012' and y.month='9' and y.usertype=1

branchid
12
13

 select * from userFORM where branchid not in (Select x.branchid from userfORM x inner join formA1 y on x.userid=y.userid where y.userid=x.userid and  y.year='2012' and y.month='9' and y.usertype=1)

**********************************OUTPUT*************************************

userid
usertype
name
branchid
username
4
1
KAAL     
14
K        

 

 

 

No comments :