Assert Student Mysql Query Matches Expected Results
Validates if the student's MySQL query matches the expected query
Location of the snippet: databases/mysql/assert_student_mysql_query_matches_expected_results
This assertion validates whether a student's MySQL query matches the expected results when executed against a specified database. It is useful for checking if the student's query correctly retrieves the intended data from the database.
| Device Type |
|---|
| On-device |
Variables:
| Variable Name | Variable Description | Type | Required? | Default |
|---|---|---|---|---|
correct_query | The correct query | `` | Yes | |
database_name | The name of the database to connect to | string | Yes | |
conn_kwargs | ADVANCED. Leave empty. Should be a literal dictionary that will be parsed in the execution environment | string | No |
Examples:
1. Basic SELECT Query Match
This example checks if the student's MySQL query exactly matches a simple SELECT statement.
Scenario: Students need to retrieve all data from the employees table in the company_db database.
Task:
Write a MySQL query to select all columns from the employees table in company_db database.
Solution:
SELECT * FROM employees;
Snippet for the assertion:
| Variable Name | Value |
|---|---|
correct_query | SELECT * FROM employees; |
database_name | company_db |
2. Specific Columns and WHERE Clause Match and connection kwargs
This example validates a query that selects specific columns and includes a WHERE clause for filtering and includes connection kwargs.
Scenario: Students are asked to find the name and email of users whose age is greater than 25 in the users table within the website_db database.
Task:
Write a MySQL query to get the name and email of users older than 25 from the users table. To login to the database, use the username admin and password securepassword.
Solution:
SELECT name, email FROM users WHERE age > 25;
Snippet for the assertion:
| Variable Name | Value |
|---|---|
correct_query | SELECT name, email FROM users WHERE age > 25; |
database_name | website_db |
conn_kwargs | {"user": "admin", "password": "securepassword"} |