This question already has answers here:
select rows that doesn´t have a value in one column, and have the same ID (2 answers)
Closed 12 hours ago.
I need to select only those product which is not having language-id "en-ZA".
In the below example I need to select only product number "102".
| ProductNumber | Language-ID |
| ------------ | ------------ |
| 100 | En-Us |
| 100 | En-ZA |
| 100 | fr |
| 101 | En-Us |
| 101 | En-ZA |
| 101 | fr |
| 102 | En-Us |
| 102 | fr |
4条答案
按热度按时间eqzww0vc1#
You can achieve this by following query using
CASE WHEN
The same query can be written using
NOT EXISTS
like the following.cigdeys32#
Try to identify Product numbers which may contain "en-ZA" by using:
That gives you a list of all Product numbers which contain 'en-ZA'.
Using that list you can sort your main list like:
vnzz0bqm3#
This is a way to do it using
left join
:We determine the rows where
Language_ID != 'En-ZA'
(100,101,102) and match it with the ones havingLanguage_ID = 'en-ZA'
(100,101), then select only the ones that are not matched usingwhere s.ProductNumber is null
Demo here
bvjveswy4#
use NOT EXISTS - it is simple and quite fast