Let’s assume I’ve got a database with two tables: people which contains person’s id and his/her birth year for each person and parents which contains the (parent_id, child_id) pairs to represent the relative relationships between people. To make the explanation easier let’s assume each person has either 0 children or 1 child. Here is an example of the data in
Tag: nested-select
Conditional Postgres Query
The PG table looks like this: I would like to write a query that only lists rows in which Name has a ‘Type A’ record but not a Type B record. This is the result I am hoping for: Answer You can use a nested select: