A comprehensive SQL query collection focused on data quality validation and bug detection in databases. This project demonstrates real-world QA skills: finding data anomalies, validating integrity, and detecting broken relationships.
This repository showcases SQL skills from a QA Engineer perspective:
- β Detecting invalid data (negative values, nulls, zeros)
- β Finding duplicates and inconsistencies
- β Validating data integrity and relationships
- β Identifying orphaned records and broken references
This is NOT about writing complex queries to show off.
This IS about writing clear, focused queries that find real bugs.
Simple e-commerce database with intentional bugs for QA practice:
users- Customer accountsproducts- Product catalogorders- Purchase orders
orders.user_id β users.id
orders.product_id β products.id
The seed data contains real-world bugs that QA engineers encounter:
- Negative totals and prices
- Zero prices and quantities
- Invalid/future dates
- Empty/null required fields
- Duplicate emails in users
- Potential duplicate orders
- Orphaned orders (user doesn't exist)
- Broken references (product doesn't exist)
- Totals that don't match calculations
sql-for-qa-testing/
βββ schema/
β βββ schema.sql # Database structure (simple & clear)
βββ data/
β βββ seed_data.sql # Test data with intentional bugs
βββ queries/
β βββ 01_basic_queries.sql # Simple filters and aggregations
β βββ 02_joins.sql # Find missing relationships
β βββ 03_edge_cases.sql # Real-world scenarios
βββ results/
β βββ bug_findings.md # Document what you found
βββ README.md
- MySQL 8.0+
- MySQL Workbench (or any SQL client)
- Create database:
CREATE DATABASE sql_qa_testing;
USE sql_qa_testing;- Run schema:
mysql -u root -p sql_qa_testing < schema/schema.sql- Load test data:
mysql -u root -p sql_qa_testing < data/seed_data.sql- Start finding bugs:
source queries/01_basic_queries.sqlEach query file is standalone and can be executed independently:
-- Example: Find negative prices
source queries/02_data_quality/find_negative_totals.sqlOr open in MySQL Workbench and execute.
- How to validate data quality systematically
- Writing queries that detect real bugs
- Understanding data relationships and integrity
- Identifying edge cases in datasets
- SQL SELECT with filters and joins
- Aggregate functions for validation
- Subqueries for data verification
- NULL handling and data anomalies
Good QA SQL queries are:
- β Clear - Easy to understand what's being checked
- β Focused - One validation per query
- β Documented - Comments explain the bug being detected
- β Actionable - Results can be directly reported
Avoid:
- β Overly complex queries that are hard to maintain
- β Multiple validations in one query
- β Queries without clear purpose
| Category | Status | Queries |
|---|---|---|
| Basic Validation | β Complete | 3/3 |
| Data Quality | β Complete | 4/4 |
| Duplicates | β Complete | 3/3 |
| Data Integrity | β Complete | 3/3 |
Total: 13 professional QA queries
This project successfully detected:
- 3 orders with invalid totals (negative/zero)
- 2 records with future dates
- 3 products with zero/negative prices
- 1 user with empty name
- 2 duplicate emails (4 users affected)
- 1 orphaned order (user doesn't exist)
- 1 broken reference (product doesn't exist)
- β How to approach data validation systematically
- β What questions to ask about data integrity
- β How to prioritize which checks matter most
- β Writing queries that find real bugs
- β Basic SELECT with meaningful WHERE clauses
- β JOINs to detect missing relationships
- β Aggregations (COUNT, SUM) for validation
- β NULL handling (IS NULL, COALESCE)
- β Window functions (RANK, LAG) for pattern detection
- β Common Table Expressions (CTEs) for readable logic
- β Stored Procedures for automated validation
- β Database Views for data abstraction
Why? Professional QA Automation requires scalable and maintainable code. By using Views and Procedures, we centralize validation logic and eliminate redundant queries.
Data Integrity: 86.67% (13 out of 15 orders are valid)
This is a personal learning project, but suggestions are welcome!
- GitHub: https://github.com/ChandeDeVargas
- LinkedIn: https://www.linkedin.com/in/chande-de-vargas-b8a51838a/
This project is open source and available under the MIT License.
β If this project helps you learn SQL for QA, give it a star!