Brandon Brandon - 19 days ago 5
SQL Question

SQL: Only showing entries where two rows match

I had to write a query that would do the following:
Join TableA.account_num and TableB.seed_acctnum
Show data that was older than 5 days and is the disposition of 2000
Thank you all for your assistance, I was able to figure it out with this code:

SELECT
ds.seed_acctnum
FROM
dbtr_status ds

INNER JOIN dbtr_clnt_generl_inf dcgi ON dcgi.account_num = ds.account_num

WHERE
dcgi.date_listed BETWEEN current_date - 40 AND current_date - 5 AND
ds.disposition = '2000'

GROUP BY ds.seed_acctnum

The current_date - 40 is only there as a limiter so the query runs faster. If there is anyway to further optimize this (tables have thousands of rows) please let me know, I would love to learn. At this moment the query takes about 32 seconds to run.

Answer
SELECT * FROM TABLEA A
JOIN TABLEB B ON
A.ACCOUNT_NUMBER = B.SEED_ACCOUNT_NUMBER
WHERE --any other conditions