Sobes.tech
Intern

Task 4 List all companies that have no transactions in the last 30 days. Use JOIN (without subquery in WHERE).

sobes.tech AI

Answer from AI

To list all companies that have no transactions in the last 30 days, using JOIN without a subquery in WHERE, you can apply a LEFT JOIN and filter by NULL in the JOIN condition or in the WHERE clause. Example in SQL:

SELECT c.*
FROM companies c
LEFT JOIN transactions t
  ON c.company_id = t.company_id
  AND t.transaction_date >= CURRENT_DATE - INTERVAL '30 days'
WHERE t.transaction_id IS NULL;

Here, we join the companies table with transactions from the last 30 days. If there are no transactions, the fields from transactions will be NULL, and such companies are selected.