How can you find records that are not present in the first table when you have an incremental table with the same structure?
💡 Model Answer
To identify rows that exist in the incremental table but not in the source table, you can use a LEFT JOIN with a NULL check or a NOT EXISTS subquery. For example:
SELECT i.*
FROM incremental_table i
LEFT JOIN source_table s
ON i.id = s.id
WHERE s.id IS NULL;
This returns all rows from incremental_table whose primary key id does not match any row in source_table. Alternatively, using NOT EXISTS:
SELECT i.*
FROM incremental_table i
WHERE NOT EXISTS (
SELECT 1 FROM source_table s WHERE s.id = i.id
);
Both approaches run in O(n) time relative to the number of rows, assuming an index on the join key. The choice depends on readability and database optimizer preferences. The key idea is to compare the unique identifiers of the two tables and filter out matches, leaving only the new or missing records.
Sign in to unlock the rest of this answer
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500