'In SQL filter out one column records based on different column condition
I have 2 columns Source_System, SBG_NAME. I want to filter out Source_System Microsiga for SBG_NAME PMT
Data set is like this:
| Source_System | SBG_Name |
|---|---|
| CIP300 | PMT |
| Microsiga | PMT |
| CIP900 | HBT |
| Microsiga | HBT |
The output should be
| Source_System | SBG_Name |
|---|---|
| CIP300 | PMT |
| CIP900 | HBT |
| Microsiga | HBT |
Solution 1:[1]
Or flipping SChnurres answer, and just not selection what you don't want
SELECT
Source_System
,SBG_Name
FROM VALUES
('CIP300','PMT'),
('Microsiga','PMT'),
('CIP900','HBT'),
('Microsiga','HBT')
v(Source_System, SBG_Name)
WHERE NOT(Source_System = 'Microsiga' and SBG_Name = 'PMT');
gives:
| SOURCE_SYSTEM | SBG_NAME |
|---|---|
| CIP300 | PMT |
| CIP900 | HBT |
| Microsiga | HBT |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Simeon Pilgrim |
