![](uploads/sql-664d92ec9661c.png)
SELECT column1, column2
FROM table_name
WHERE condition;
Explanation:
SELECT first_name, last_name
FROM employees
WHERE department = 'IT';
This query selects the first name and last name of employees from the employees
table where the department is 'IT'.
Here are some common SQL data types:
Data Type | Description |
---|---|
INT | Integer (whole number) |
VARCHAR(n) | Variable-length character string with a maximum length of n characters |
DATE | Date in the format 'YYYY-MM-DD' |
Joins are used to combine rows from two or more tables based on a related column between them. Here are the types of joins:
SELECT employees.first_name, departments.department_name
FROM employees
INNER JOIN departments ON employees.department_id = departments.department_id;
This query selects the first name of employees and the department name they belong to by joining the employees
table with the departments
table based on the department_id
.
SQL provides various functions to perform calculations, manipulate strings, and more. Here are some common SQL functions:
SELECT AVG(salary) AS average_salary
FROM employees
WHERE department = 'Finance';
This query calculates the average salary of employees in the 'Finance' department.