Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have a table like


id status statusid complaintto
1 open 14 employee
1 pending 15 administration
1 closed 16 xyz
2 open 14 employe
2 pending 15 administration
2 closed 16 xyz
3 open 14 employe
3 pending 15 administration
3 pending 15 xyz


i don't want to show id closed

3rd id record will be shown

thankx
Posted

Not Clear but,If you don't want to show the record with closed status,do like this,
SQL
SELECT id,status,statusid,complaintto from Table where status!='closed'


Or if you want to omit status,then just leave status from the query.
SQL
SELECT id,statusid,complaintto from Table where status!='closed'


Edit:2
You may get it from two way by using where clause.
SQL
select distinct a.id from #table1 as a inner join
 (select id,count(id) as Count1 from #Table1 where status!='closed' group by id) as b
  on a.id=b.id and b.Count1=3 

Or simply do like this,
select id from #table1 where statusid!=16 and ID=3 and status='pending' and complaintto='xyz'
 
Share this answer
 
v3
Comments
Parazival 28-Feb-15 0:30am    
it will show

id status statusid complaintto
1 open 14 employee
1 pending 15 administration
2 open 14 employe
2 pending 15 administration
3 open 14 employe
3 pending 15 administration
3 pending 15 xyz

but i want answer like

id
3
Parazival 28-Feb-15 0:33am    
i mean if any id(1,2,3) have (16)

that id should not show to me
Rajesh waran 28-Feb-15 1:21am    
I have updated my solution.Have a look.
try this:
exclude the id which are having closed status and then select the rest
you can use self joins too.
SQL
SELECT * FROM [Sample] where id not in
(
    SELECT id from [sample] where statusid = 16 -- for closed
)
 
Share this answer
 
v2
Comments
Parazival 28-Feb-15 1:25am    
my 5+ niceeeee answer awesome.............

i got the answer

thanks friend
Schatak 28-Feb-15 2:56am    
Good, then accept the solution :P
Parazival 28-Feb-15 6:57am    
where can i dowload the xml full material

thankx
Schatak 2-Mar-15 23:58pm    
which xml?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900