I have 2 tables:
video_real
device_id | video_definition
1 | 360
1 | 480
(2 rows)
video_all
device_id | video_definition
1 | 360
1 | 480
1 | 540
1 | 720
1 | 1080
I want to return
device_id | video_definition
1 | 540
1 | 720
1 | 1080
How do I do this?
2
Answers
This is pretty much the definition of an "anti-join". You can do:
You can use the
EXCEPT
operator. This compares the results from both queries and removes any matching values.A more thorough explanation can be found here.
Schema (PostgreSQL v15)
Query #1
View on DB Fiddle