SQL and Python Interview Questions Guide
SQL and Python Interview Questions Guide
SQL commands can be broadly categorized into DDL (Data Definition Language), DML (Data Manipulation Language), and DCL (Data Control Language). DDL commands, such as CREATE, ALTER, and DROP, are used to define and manage database structures like tables and schemas. DML commands, like INSERT, UPDATE, and DELETE, are used for manipulating data within those structures. DCL commands, such as GRANT and REVOKE, handle permissions and access controls within the database .
Python dictionaries store data as key-value pairs, allowing for constant time complexity when retrieving, adding, or deleting elements using keys. Unlike lists, which are ordered collections of items accessed by index, and tuples, which are immutable sequences, dictionaries are unordered and mutable. This makes dictionaries ideal for scenarios where it is necessary to quickly locate data without relying on sequential access .
Python is considered versatile due to its readability, simplicity, and extensive standard library. Its key features include dynamic typing, interpretability, and a large collection of third-party modules, which allow for rapid development and integration across various domains such as web development, data analysis, and artificial intelligence. Python’s cross-platform nature and active community support further enhance its versatility .
The WHERE clause is used to filter rows before any groupings are made in the result set, typically based on conditions on individual records. The HAVING clause, however, is used to filter records after they have been grouped by the GROUP BY clause, allowing for conditions to be applied to aggregated data. Thus, WHERE is for raw data filtering, while HAVING is for aggregated data filtering .
Aggregate functions operate on a set of values and return a single value, such as SUM(), AVG(), COUNT(), MAX(), and MIN(), and are typically used with GROUP BY clauses to perform operations on groups of rows. Scalar functions, on the other hand, operate on individual values and return a single value for each input, such as UPPER(), LOWER(), and LENGTH(). They are often used for manipulating data in SELECT statements .
ORDER BY sorts the result set based on specified column(s), allowing for either ascending or descending sorting. GROUP BY aggregates data based on selected columns, allowing for aggregate functions like SUM() and COUNT(). WHERE filters the dataset before any aggregation or sorting, providing conditional logic to exclude certain rows. Together, these clauses help mold data retrieval from filtering raw data to presenting aggregated and ordered information .
An inner join retrieves records that have matching values in both tables being joined. It excludes records without corresponding matches. In contrast, a left join includes all records from the left table and the matched records from the right, a right join does the opposite, and a full join includes all records when there is a match in either table. Inner joins are often used when you only need records with exact matches across both tables .
Aggregate functions perform operations on multiple values to return a summary, such as COUNT() for counting rows, SUM() for computing totals, and AVG() for calculating averages. These functions are essential in generating reports, such as finding total sales, average salary, or the count of employees in a department. Aggregate functions allow for data analysis and insights from large data sets .
SQL is a standard language for querying and managing data in a relational database, whereas MySQL is a specific relational database management system (RDBMS) that uses SQL as its language. MySQL provides additional functionalities and is designed to efficiently store, modify, and retrieve data .
A primary key is a unique identifier for each record in a table, ensuring that no two rows can have the same primary key value. A foreign key, on the other hand, is a field in a table that links to the primary key of another table, establishing a relationship between tables. These keys help enforce referential integrity, ensuring that data is consistent across related tables .