Skip to content
Advertisement

PostgreSQL result of first query used in second query

Sample Data:

I need to run a query with the following criteria:

So far it was easy but now comes the part where I am stuck:

The result should look like this:

My main problem here is that the old_numbers can be in records that don´t match my criteria (dates within a month and password_mod = false). But these two criterias are mandatory.

I´ve made two queries that do both steps. Now I need a good way to combine them.

Query1:

Query2:

Advertisement

Answer

One intuitive/user-readable way to write the query would be with a CTE:

Disclosure: I work for EnterpriseDB (EDB)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement