'JOIN of two subqueries returns 1000x more rows than the total both subqueries combined

Im using a Postgres DB via PGAdmin 4.13

For the sake of performance, I'm trying to run two separate selects, and then do an inner join on them. However, it appears to be running every row against every other row, and I'm returning a table that exponentially too large (literally 1000x bigger than either query alone returns.)

First query returns 4320 rows:

SELECT * FROM schema_name.table_one WHERE resultset_name LIKE 'My test results%'

Second query returns 1080 rows:

SELECT * FROM schema_name.table_two WHERE resultset_name LIKE 'My test results%'

Join returns 518000 rows :D

SELECT * 
FROM
(SELECT * FROM schema_name.table_one WHERE resultset_name LIKE 'My test results%') t1 
INNER JOIN
(SELECT * FROM schema_name.table_two WHERE resultset_name LIKE 'My test results%') t2
ON t1.resultset_name = t2.resultset_name

Attempting to run a more traditional inner or left join runs forever...

SELECT * 
FROM schema_name.table_two
INNER JOIN schema_name.table_one 
ON schema_name.table_two.resultset_name = schema_name.table_one.resultset_name
WHERE schema_name.table_two.resultset_name LIKE 'My test results%'

NOTE: That the WHERE schema_name.table_two.resultset_name LIKE 'My test results%' requires the schema_name.table_two. to be in the WHERE clause, otherwise it errors on an ambiguous column name.

QUESTION 1: Why is the JOIN from two subselects returning so many rows? My intention was to slim down memory use - by returning two smaller tables - and then joining only the data in those tables. Can the query be corrected to do this?

QUESTION 2: If my initial join of two subselects cannot work the way I want it to, how can I filter down the memory use for the traditional join?

EDIT: For additional clarity

Excel description of tables



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source