-5

So basically i've a table like this.

+--------+----------+   
|   name |  Group   |  
+--------+----------+   
|   xxxx |   1      |  
|   yyyy |   1      |  
|   xxxx |   2      |  
|   yyyy |   3      |  
|   xxxx |   4      |  
+--------+----------+

and i don't want to display any records that have name xxxx in their group.

Ilyes
  • 14,640
  • 4
  • 29
  • 55
Zackk
  • 73
  • 2
  • 9

2 Answers2

1

You seem want :

select t.*
from table t
where not exists (select 1 from table t1 where t1.group = t.group and t1.name = 'xxxx')
Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
  • your awswer seem to be right but i got some problem with it cause im using CTE and my query after CTE implementation looks like this SELECT DISTINCT c.TWG_Kod as NAME, g1.TwG_Kod as GROUP, k.twr_nazwa, m.MAG_Nazwa, m.MAG_Kod FROM CTE c join cdn.TwrGrupy g1 with (nolock) on c.TwG_GIDNumer = g1.TwG_GrONumer. And i don't know how to manage to use it in your querry cause of column name duplication – Zackk Dec 04 '18 at 11:32
-1

You need a subquery at first to identify groups you do not need. then you need to filter it from main query

SELECT * FROM Table1 
Where group not in ( select group from Table1 where name != 'xxxx')
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72