HomeInterview QuestionsGiven scenarios, write queries to validate data.

Given scenarios, write queries to validate data.

🟡 Medium Coding Junior level
1Times asked
May 2026Last seen
May 2026First seen

💡 Model Answer

For each scenario, identify the key validation rule. 1) Row count consistency: SELECT COUNT() FROM table1; SELECT COUNT() FROM table2; 2) Primary key uniqueness: SELECT key_col, COUNT() FROM table GROUP BY key_col HAVING COUNT() > 1; 3) Referential integrity: SELECT t1.id FROM table1 t1 LEFT JOIN table2 t2 ON t1.id = t2.ref_id WHERE t2.ref_id IS NULL; 4) Data type and range checks: SELECT * FROM table WHERE numeric_col NOT BETWEEN 0 AND 100; 5) Checksum comparison: SELECT MD5(GROUP_CONCAT(col1, col2 ORDER BY id)) AS chk FROM table; Compare chk across environments. These queries provide quick sanity checks and help catch migration or integration errors.

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 — invisible to screen sharing.

Get Assisting AI — Starts at ₹500