SQL_Interview_Questions_Answers_Part1
SQL_Interview_Questions_Answers_Part1
Q: What is SQL?
A: SQL (Structured Query Language) is a programming language designed for managing data in relational databases.
A: SELECT specifies the columns, FROM specifies the table, and WHERE filters rows based on conditions.
A: Use the WHERE clause: SELECT * FROM table_name WHERE column_name = 'value';
A: AND requires all conditions to be true. OR requires at least one condition to be true.
A: Functions that perform a calculation on a set of values: COUNT, SUM, AVG, MIN, MAX.
Q: How do you group rows based on a column and apply an aggregate function?
A: Use GROUP BY: SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;
A: Used to filter groups after aggregation. Different from WHERE which filters rows.
A: Aliases rename columns or tables using AS: SELECT column_name AS alias FROM table_name;
A: Joins combine rows from two or more tables based on a related column.
A: Use INNER JOIN when both tables must have matching records, LEFT JOIN to include all from the left table, etc.
Q: What is a self-join?
A: Use IN or NOT IN: SELECT * FROM table WHERE column IN ('A', 'B');
A: Use BETWEEN: SELECT * FROM table WHERE column BETWEEN 10 AND 20;
A: INSERT INTO table VALUES (...), UPDATE table SET column=... WHERE ..., DELETE FROM table WHERE ...