Fundamentals Interview Questions
Comprehensive fundamentals interview questions and answers for SQL. Prepare for your next job interview with expert guidance.
Questions Overview
1. What is SQL?
BasicSQL (Structured Query Language) is a standard language for managing and manipulating relational databases. It is used for querying, updating, and managing data in databases. Common SQL commands include `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `CREATE`, and `ALTER`.
2. What is the difference between `INNER JOIN` and `OUTER JOIN`?
Moderate`INNER JOIN` returns only the rows that have matching values in both tables, while `OUTER JOIN` (including `LEFT JOIN` and `RIGHT JOIN`) returns all rows from one table and the matching rows from the other, filling in `NULL` where there are no matches.
3. How do you create a table in SQL?
ModerateA table is created using the `CREATE TABLE` statement. For example: ```sql CREATE TABLE employees ( id INT PRIMARY KEY, name VARCHAR(100), age INT, department VARCHAR(50) ); ```
4. What is a primary key in SQL?
BasicA primary key is a unique identifier for records in a table. It ensures that no duplicate values exist in the column or combination of columns marked as the primary key. Each table can have only one primary key.
5. Explain the use of `GROUP BY` in SQL.
Moderate`GROUP BY` is used to group rows that share a common value in specified columns. It is typically used with aggregate functions like `COUNT()`, `SUM()`, `AVG()`, `MAX()`, and `MIN()` to return grouped results. For example: `SELECT department, COUNT(*) FROM employees GROUP BY department;`.