SQL (Structured Query Language) is a standard programming language specifically designed for managing and manipulating relational databases. It allows users to create, read, update, and delete data.
A primary key is a unique identifier for a record in a table, ensuring that no two rows have the same value in that column.
A JOIN clause is used to combine rows from two or more tables based on a related column between them.
INNER JOIN returns only the rows where there is a match in both tables.
LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table and the matched rows from the right table. If there is no match, NULL values are returned for columns from the right table.
Creates a new table named 'employees' with specified columns.
SQL commands are classified into several types: DDL (Data Definition Language), DML (Data Manipulation Language), DCL (Data Control Language), and TCL (Transaction Control Language).
Inserts a new employee record into the employees table.
Updates the last name of an employee based on their ID.
Deletes an employee record based on their ID.
Adds a new column 'email' to the employees table.
Modifies the data type of the 'department_id' column to BIGINT.
Renames the employees table to staff.
Removes the employees table from the database.
Retrieves all columns and rows from the employees table.
Retrieves only the first_name and last_name columns.
Selects all employees in the Sales department.
Retrieves all employees ordered by hire date in descending order.
Returns the total number of records in the employees table.
Counts the number of employees in each department.
Retrieves departments with more than 10 employees.
Joins employees and departments tables to get employee names with their respective department names.
Adds a new employee record to the employees table.
Updates the department of John Doe.
Deletes records of employees with the last name Doe.
Identifies duplicate employee names.
Retrieves unique department names from the employees table.
Selects employees who belong to the Sales department using a subquery.
Retrieves the first five records from the employees table.
This query retrieves the second highest salary from the employees table using a subquery.
This query retrieves the second highest salary by using DISTINCT to filter unique salary values.
This query utilizes a CTE to rank salaries and retrieve the second highest.
This query groups salaries and retrieves the second highest using HAVING.
This query finds the second highest salary by counting distinct salaries.
INNER JOIN returns only matching rows; LEFT JOIN returns all rows from the left table and matching rows from the right; RIGHT JOIN returns all rows from the right table and matching rows from the left.
A subquery is a query nested inside another query, used to retrieve data that will be used in the main query.
Normalization is the process of organizing data to minimize redundancy and improve data integrity.
GROUP BY aggregates results based on one or more columns.
Indexes are data structures that improve the speed of data retrieval operations on a database table at the cost of additional space and maintenance time.
A stored procedure is a precompiled collection of one or more SQL statements that can be executed as a single unit.
A view is a virtual table based on the result set of a SQL query. It can simplify complex queries.
Query performance can be improved by indexing, optimizing queries, avoiding unnecessary columns, and analyzing query execution plans.
CROSS JOIN returns the Cartesian product of two tables, combining all rows from the first table with all rows from the second table.
A SELF JOIN is used to join a table to itself to compare rows within the same table.
NATURAL JOIN automatically joins tables based on columns with the same names and types.
FULL OUTER JOIN returns all records when there is a match in either left or right table records.
LEFT JOIN can include multiple conditions using AND.
INNER JOIN can be combined with aggregate functions to summarize data.
LEFT JOIN can use COALESCE to replace NULL values with a default value.
Joining multiple tables can be done by chaining JOIN statements.
This query retrieves all employee names that start with the letter 'A'.
This query finds all employee names that contain the substring 'son'.
This query retrieves all employee names that end with 'n'.
This query retrieves all employee names that start with any vowel using regular expressions.
This query finds all employee names that have 'a' followed by any two characters and then 'e'.
This query retrieves names that are exactly five characters long.