MYSQL Notes
MYSQL Notes
DATA:
Data is a statistically raw and unprocessed information. In computer language a piece of information
that can be translated into a form for efficient moment and processing is called data.
DATABASE:
Database is a collection of data that is organized which is also called structured data. It can be stored
in a computer system. It can be managed through database management system. In a database, data is
organized into tables consisting of rows and columns and it is indexed so data can be updated, expanded, and
deleted easily.
TYPES OF DATABASES:
Relational Database
Centralized Database
NoSQL Database
Distributed Database
Cloud Database
Network Database
Object oriented Database
Hierarchical Database
WHY WE USE DATABASE?
Data Retrieval:
Database provide query that enable efficient and access of specific data.
Data Organization:
Database allow for the structured organization of data into tables, rows, columns.
Manage:
The structured data makes easier to understand and manage large sets of data.
Relationship between data:
In relationship database data in different tables can be related to each other.
Concurrency control:
Databases are designed to handle multiple users or process accessing and modifying data
simultaneously.
Data Security:
This helps protect sensitive information and ensures that only authorized users can interact with
the database.
Data Recovery:
Database often include features for data backup and recovery. Regular backups can be
performed to safeguard against data loss due to software errors, hardware failures or other
issues.
DBMS:
DBMS stands for Database Management System. It is a software system that facilitates the creation,
organization, and management of database.
The primary purpose of DBMS is to provide a structured way to store retrieve and manage data.
TYPES OF DBMS
RDBMS (Relational Database Management System):
It organizes data into tables with rows and columns.
Tables can have relationship with each other.
Ex: MySQL, PostgreSQL, Oracle database, Microsoft SQL server
NoSQL DBMS:
It is suitable for unstructured or semi-structured data.
Ex: Mango DB, Cassandra, Couchbase
Object Oriented DBMS:
It stores the data in the form of objects, which are instance of classes.
Ex: db4o
Graph DBMS:
It optimized for storing and querying graph data.
Ex: Neo4j, Arango DB
In-memory DBMS:
It stores the data primarily in the computers main memory (RAM) for faster access.
Ex: Redis, SAP HANA
Distributed DBMS:
It spreads data across multiple servers or locations.
Ex: Google cloud spanner, Amazon Aurora
Columnar DBMS:
It stores the data in columns rather that rows optimizing for analytics.
Ex: Apache Cassandra, Amazon Redshift
Time Series DBMS:
It optimized for handling time stamped data such as financial market data.
Ex: Influx DB, Open TSDB
Document Oriented DBMS:
It stores data in semi-structured documents like Json or xml.
Ex: Mango DB, Couch DB
XML DBMS:
It handles XML data.
Ex: BaseX
SQL STATEMENTS
It consists of various statements used to perform different operations on a database.
1. SELECT: It retrieves data from one or more tables.
2. INSERT: Adds new record to a table.
3. UPDATE: Modifies existing records in a table.
4. DELETE: Removes records from a table.
5. CREATE: Creates new database objects such as tables and indexes.
6. ALTER: It modifies the structure of an existing database object.
7. DROP: Deletes a database object.
SQL is not case sensitive but conventionally keywords are written in uppercase for better readability.
Semicolons are used to terminate SQL statements.
MySQL COMMANDS
In MySQL the provided commands are used to perform various actions related to databases.
SHOW DATABASES:
This command displays a list of existing databases in your MySQL server.
CREATE DATABASE mydatabase:
This command creates a new database named mydatabase. After crating new database SHOW
DATABASES command is used to verify that the new database(mydatabase) has been
successfully created.
USE mydatabase:
This command is used to switch to the specified database.
DROP DATABASE mydatabase:
This command deletes the specified database permanently.
EXIT:
This command is used to exist the MySQL command line interface.
QUIT:
Similar to EXIT.
INTRODUCTION TO TABLES
A table is a fundamental structure used to organize and store data.
It is a 2D structure composed of rows and columns.
Each row in a table represents a record while each column represents a specific attribute.
CELL
The intersection of a row and column. It contains single data value.
PRIMARY KEY
It is a unique identifier for each record in the table.
TABLE NAME
Each table is given a unique name within the database.
DATATYPES
Datatypes define the kind of data that can be stored in a column.
The type of values are fixed or variable.
NUMERIC:
These datatypes can include exact numeric datatypes
For ex: integer, float, bits
FLOAT(m,d):
It is a floating-point number that cannot be unsigned. It defines the display length(m) and the
number of decimals(d).
For ex: float(10,2) which means 10 is the total number of digits including decimals where 2 is
the number of decimals.
It takes 24 places and requires 2 Bytes for storage.
DOUBLE(m,d):
In this datatype decimal decision can go to 53 places and it requires 8 Bytes for storage.
It cannot be unsigned.
DECIMAL(m,d):
In this datatype each decimal corresponds to byte.
BIT(m):
It is used to store the bit values into the table column.
Here m defines number of bit per value that has a range of 1 to 64.
BOOL:
It is used only for the true and false condition. It is considered numeric value 1 as True and 0
as False.
BOOLEAN:
Similar to BOOL.
STRING DATATYPES
The string datatypes is used to hold plain text and binary data.
NAME MAX SIZE FIXED/VARIABLE
CHAR(size) 255 characters Fixed length string
VARCHAR(size) 255 characters Variable length string
TINYTEXT(size) 255 characters Number of characters to store
TEXT(size) 65535 Number of characters to store
MEDIUM(size) 16777215
LONGTEXT(size) 4GB or 4294967295
BINARY(size) 255 characters Number of binary characters
stored or fixed length string
VARBINARY(size) 255 characters Variable length string
BINARY LARGE OBJECT DATATYPE (BLOB)
TINYBLOB It can hold a max size of 255 bytes
BLOB It can hold a max size of 65535 bytes
MEDIUMBLOB It can hold a max size of 16777215 bytes
LONG It can hold a max size of 4GB/ 4294967295
bytes
SQL COMMANDS
TRUNCATE LOCK
DATA DEFINITION LANGUAGE (DDL)
CREATE:
This command is used to create a new database, table, view or other database objects.
DROP:
DROP is used to delete an existing database object, table.
It permanently removes the specified object.
ALTER:
The ALTER command is used to modify the structure of an existing database object such as
table.
TRUNCATE:
TRUNCATE is used to quickly delete all rows from a table.
COMMANDS
SHOW DATABASES;
CREATE DATABASE mydatabase;
SHOW DATABASES;
USE mydatabase;
DROP DATABASE mydatabase;
EXIT;
DDL
SHOW DATABASES;
CREATE DATABASE CODEGNAN;
USE CODEGNAN;
CREATE TABLE EMPLOYEES(EMP_ID CHAR(5),
-> FNAME VARCHAR(50),
-> LNAME VARCHAR(50),
-> AGE INT, DOJ DATE,
-> ADDRESS TINYTEXT,
-> DEPT VARCHAR(20));
SHOW TABLES;
DESC EMPLOYEES;
SHOW COLUMNS FROM EMPLOYEES;
DESC EMPLOYEES;
DESC EMPLOYEES;
ALTER TABLE EMPLOYEES
-> CHANGE COLUMN LNAME LASTNAME VARCHAR(60);
DESC EMPLOYEES;
SHOW TABLES;
DESC departments;
DROP TABLE departments;
SHOW TABLES;
DESC codegnan_emp;
DML
INSERT INTO CODEGNAN_EMP (EMP_ID, FIRSTNAME, LASTNAME, AGE, DOJ, ADDRESS, DEPT)
-> VALUES ('E001', 'John', 'Doe', 30, '2023-01-01', '123 Main St', 'IT');
INSERT INTO CODEGNAN_EMP (EMP_ID, FIRSTNAME, LASTNAME, AGE, DOJ, ADDRESS, DEPT)
-> VALUES
-> ('E001', 'John', 'Doe', 30, '2023-01-01', '123 Main St', 'IT'),
-> ('E002', 'Jane', 'Smith', 25, '2023-02-15', '456 Oak St', 'HR'),
-> ('E003', 'Bob', 'Johnson', 35, '2022-12-10', '789 Pine St', 'Finance');
UPDATE CODEGNAN_EMP
-> SET ADDRESS = '259 Spark St'
-> WHERE EMP_ID = 'E001';
ROLLBACK
START TRANSACTION;
ROLLBACK;
SAVEPOINT
START TRANSACTION;
SAVEPOINT my_savepoint;
SELECT
SELECT * FROM CODEGNAN_EMP;
WHERE CLAUSE
The WHERE clause is used to filter records based on specific conditions in a query, allowing you to retrieve
data that meets specific criteria.
Ex: SELECT * FROM table WHERE column = ‘value’;
It means retrieves rows where the specific column has specific value.
SHOW DATABASES;
USE CODEGNAN;
SHOW TABLES;
ARITHMETIC OPERATORS
COMPARISION OPERATORS
o <= checks if left value is less than or equal to the right value
o >= checks if left value is greater than or equal to the right value
o ‘BETWEEN’ & ‘AND’ : These are used to filter the results within a specific range
o ‘NOT BETWEEN’ & ‘AND’ : These are used to filter the results outside a specific range
o ‘NOT IN’ : It is used to filter the results excluding a list of specified values.
o ‘IS NOT NULL’ : It is used to filter results where a column is NOT NULL.
LOGICAL OPERATORS
o ‘AND’ : It is used to combine conditions. It returns TRUE only all conditions are TRUE
o ‘OR’ : It is used to combine conditions, it returns TRUE if atleast one of the condition is TRUE.
o ‘NOT’ : It is used to negate a condition. It returns TRUE if the condition is FALSE and vice
versa.
CREATE DATABASE librarydb;
USE librarydb;
CREATE TABLE BOOKS (
-> book_id INT PRIMARY KEY,
-> title VARCHAR(100),
-> author VARCHAR(50),
-> genre VARCHAR(50),
-> publication_year INT,
-> price DECIMAL(8, 2)
-> );
DESC books;
INSERT INTO books (book_id, title, author, genre, publication_year, price) VALUES
-> (1, 'The Great Gatsby', 'F. Scott Fitzgerald', 'Fiction', 1925, 15.99),
-> (2, 'To Kill a Mockingbird', 'Harper Lee', 'Fiction', 1960, 12.50),
-> (3, '1984', 'George Orwell', 'Dystopian', 1949, 10.99),
-> (4, 'The Catcher in the Rye', 'J.D. Salinger', 'Fiction', 1951, 14.75);
-- Arithmetic Operators
UPDATE books SET price = price + 5.00;
SELECT * FROM books;
UPDATE books SET price = price - 3.00 WHERE publication_year < 1960;
SELECT * FROM books;
-- Logical Operators
SELECT * FROM books WHERE genre = 'Fiction' AND price > 15.00;
SELECT * FROM books WHERE genre = 'Dystopian' OR genre = 'Science Fiction';
SELECT * FROM books WHERE NOT genre = 'Fiction';
WARNINGS
In MySQL warnings are the issues that might effect the outcome of a query but don’t stop its execution.
ERRORS
These are the issues that prevent a query from completing successfully, when an error occur the server
typically stops processing the query returns an error message.
-- Warnings
SELECT 10/2;
SELECT 10 / 0;
SHOW WARNINGS;
Use codegnan;
CREATE TABLE mytable (
id INT PRIMARY KEY,
name VARCHAR(5)
);
SELECT '123abc' + 1;
SHOW WARNINGS;
STRING FUNCTIONS
String functions are used to manipulate and operate on characters or text data.
There are different types of string functions:
Alias: it is used to give a column or an expression a temporary name, making the output more
reliable.
Product_name AS ‘PRODUCT’
CONCAT: it concatenates two or more strings.
#String Functions
DESC PRODUCTS;
CONSTRAINTS
They are used to limit the type of data that can go into a table.
Constraints are used to specify rules for the data in a table.
These ensures the accuracy and reliability of the data in the table.
The constraints are
NOT NULL
UNIQUE
PRIMARY KEY
DEFAULT
CHECK
FOREIGN KEY
DEFAULT
The DEFAULT constraint is used to provide a default value for a column if no value is
explicitly specified during an INSERT operation. It is optional.
PRIMARY KEY
It is a unique identifier for each Record in a table ensuring that no 2 rows have the same
values in the desired column.
UNIQUE
The UNIQUE constraint ensures that all values in the specified column are distinct.
Preventing duplicate entries within that column in a table.
A table can have only one primary key.
A table can have multiple unique keys constraints.
A primary key column cannot contain null values.
A unique key can have null values.
AUTO INCREMENT
AUTO INCREMENT is used to automatically generate unique, incremental values for a
column, typically it is a primary key.
CHECK
CHECK constraint is used to enforce conditions on the values. That can be inserted into a
column.
It ensures that the data enter into a specific column meets certain criteria specified by the
CHECK constraint.
FOREIGN KEY
It is a field or collection of fields in one table that refers to the primary key of another table.
The table with the foreign key is called the child table and the table with the primary is called
the reference or parent table.
-- NOT NULL
SHOW DATABASES;
USE CODEGNAN;
SHOW TABLES;
DESC STUDENT;
DESC PERSONS;
-- PRIMARY KEY
CREATE TABLE Persons1 (
-> ID int NOT NULL PRIMARY KEY,
-> Name varchar(45) NOT NULL,
-> Age int,
-> City varchar(25));
DESC PERSONS1;
DESC PERSONS1;
-- UNIQUE
DESC SHIRTBRANDS;
INSERT INTO ShirtBrands(Id, BrandName, Size) VALUES(1, 'Pantaloons', 38), (2, 'Cantabil', 40);
DESC ANIMALS;
-- CHECK
DESC PERSONS2;
INSERT INTO Persons2(Id, Name, Age)
-> VALUES (1,'Robert', 28), (2, 'Joseph', 35), (3, 'Peter', 40);
DESC PERSONS3;
DESC ORDERS;
INSERT INTO Orders (Order_ID, Order_Num, Person_ID) VALUES
-> (1, 5544, 2),
-> (2,3322,3),
-> (3,2135,2),
-> (4,3432,1);
ORDER BY
It means to sort the result based on one or more conditions.
Example, SELECT * FROM TABLE_NAME ORDER BY COLUMN_NAME ASE/DESC;
LIMIT
It means to limit the number of rows return in the result set.
Example, SELECT * FROM TABLE_NAME LIMIT 10;
LIKE
It means to filter based on a pattern. To find rows where a column starts with a specific value.
Example, SELECT * FROM TABLE_NAME WHERE COLUMN_NAME LIKE ‘L%’;
SELECT * FROM TABLE_NAME WHERE COLUMN_NAME LIKE ‘%CHAIR%’;
LIKE:
To filter based on a pattern.
To find rows where a column starts with a specific value:
Starts with 'L'
SELECT * FROM PRODUCTS WHERE PRODUCT_NAME LIKE 'L%';
Contains 'Electronics'
SELECT * FROM PRODUCTS WHERE CATEGORY LIKE '%ELECTRONICS%';
AGGREGATE FUNCTIONS
COUNT
It counts the total number of rows in a table.
Example, SELECT COUNT(*) FROM TABLE_NAME;
GROUP BY
It groups rows based on the specified column.
Example, SELECT COLUMN_NAME, COUNT(*) FROM TABLE_NAME GROUP BY
COLUMN_NAME;
MIN AND MAX
it finds the min and maximum values in a column.
Example, SELECT MIN(COLUMN_NAME), MAX(COLUMN_NAME) FROM
TABLE_NAME;
GROUP BY WITH MIN AND MAX
It groups rows and finds the min and maximum values for each group.
Example, SELECT COLUMN_NAME, MIN(VALUE), MAX(VALUE) FROM
TABLE_NAME GROUP BY COLUMN_NAME;
SUM AND AVG
It calculates the total sum and average of values in a column.
Example, SELECT SUM(COLUMN_NAME), AVG(COLUMN_NAME) FROM
TABLE_NAME;
GROUP BY WITH SUM AND AVG
It groups rows and calculate the total sum and average for each group.
Example, SELECT COLUMN_NAME, SUM(VALUE), AVG(VALUE) FROM
TABLE_NAME GROUP BY COLUMN_NAME;
SUBQUERIES
It uses a query within another to retrieve data or perform calculations.
Example, SELECT * FROM TABLE_NAME
WHERE COLUMN NAME = (SELECT MAX(COLUMN_NAME) FROM
TABLE_NAME);
-- Create Database
CREATE DATABASE SALES;
-- Create Table
CREATE TABLE ORDERS (
ORDER_ID INT PRIMARY KEY,
PRODUCT_NAME VARCHAR(50),
QUANTITY INT,
PRICE DECIMAL(8, 2),
ORDER_DATE DATE
);
3) Min and Max: Find the minimum and maximum quantity of products ordered.
SELECT MIN(QUANTITY) AS MIN_QUANTITY, MAX(QUANTITY) AS MAX_QUANTITY
FROM ORDERS;
Explanation: The MIN() and MAX() functions retrieve the minimum and maximum values of the quantity
column, respectively.
4) Group By with Min and Max: Find the minimum and maximum price for each product.
SELECT PRODUCT_NAME, MIN(PRICE) AS MIN_PRICE, MAX(PRICE) AS MAX_PRICE
FROM ORDERS
GROUP BY PRODUCT_NAME;
Explanation: This query uses GROUP BY to group the result set by product_name and then calculates the
minimum and maximum prices for each product.
5) Sum and Avg: Calculate the total quantity and average price of all orders.
SELECT SUM(QUANTITY) AS TOTAL_QUANTITY, AVG(PRICE) AS AVERAGE_PRICE
FROM ORDERS;
Explanation: The SUM() function calculates the total quantity, and the AVG() function calculates the average
price across all orders.
6) Group By with Sum and Avg: Calculate the total quantity and average price for each product.
SELECT PRODUCT_NAME, SUM(QUANTITY) AS TOTAL_QUANTITY, AVG(PRICE) AS
AVERAGE_PRICE
FROM ORDERS
GROUP BY PRODUCT_NAME;
Explanation: This query uses GROUP BY to group the result set by product_name and then calculates the
total quantity and average price for each product.
TIME( ):
It extracts the time part of a date or date-time expression.
Example, SELECT TIME(‘2024-01-09 15:30:45’);
Output - 15:30:45
YEAR( ), MONTH( ), DAY( ):
It extracts the year, month or day from a date.
Example, SELECT YEAR(‘2024-01-09’),
MONTH(‘2024-01-09’),
DAY(‘2024-01-09’);
NOW( ):
It returns the current date and time.
Example, SELECT NOW( );
CURDATE( ):
This functions returns the current date in ‘YYYY-MM-DD’ format.
Example, SELECT CURDATE( );
CURTIME( ):
This functions returns the current time in ‘HH:MM:SS’ format.
Example, SELECT CURTIME( );
CURRENT_TIMESTAMP( ):
This function returns the current date and time in ‘YYYY-MM-DD HH:MM:SS’ format.
Example, SELECT CURRENT_TIMESTAMP( );
DATE FORMAT:
It formats the date as specified.
Example, SELECT DATE_FORMAT(‘2024-01-09’,’%w,%m,%e,%y’);
%w – Full weekday name
%m – Full month name
%e – day of the month
%y – four digit year
DATEDIFF( ):
It calculates the difference between two dates.
Example, SELECT DATEDIFF(‘2024-01-09’,’ 2024-01-14’);
DATE_ADD( ) AND DATE_SUB( ):
It adds or subtract a specified time interval from a date.
Example, SELECT DATE_ADD(‘2024-01-09’,INTERVAL 5 DAY);
2024-01-09 : Start date
INTERVAL: It is a keyword indicating that you are adding a time interval.
5 : value, which means the number of intervals to add.
DAY : unit, it is the unit of intervals.
Example, SELECT DATE_ADD(‘2024-01-09’,INTERVAL 3 MONTH);
SELECT DATE_SUB(‘2024-01-09’,INTERVAL 3 MONTHS);
EXTRACT( ):
It extracts a part of a date or time.
Example, SELECT EXTRACT(HOUR FROM ‘2024-01-09 11:30:45’);
TIMESTAMPDIFF( ):
It calculates the difference between two timestamps.
Example, SELECT TIMESTAMPDIFF(SECOND, ‘2024-01-09 11:30:45’,
‘2024-01-09 15:30:45’);
TIMEDIFF( ):
It calculates the difference between two times.
Example, SELECT TIMEDIFF(‘11:30:45’, ‘15:30:45’);
ADDTIME( ) AND SUBTIME( ):
Adds or subtracts a time interval to a time or date-time expression.
Example, SELECT ADDTIME(‘11:30:45’, ‘15:30:45’);
Example, SELECT SUBTIME(‘11:30:45’, ‘15:30:45’);
FORMATTING DATES:
SELECT DATE_FORMAT(‘2024-01-09 11:30:45’,’%Y-%M-%D %H:%I:%S’);
%H – 2 digit hour in 24 hour format
%I – 2 digit minutes (00-59)
%S – 2digit second (00-59)
SELECT DATE_FORMAT(‘2024-01-09 11:30:45’,’DATE - %Y-%M-%D’);
DATE():
Extracts the date part of a date or datetime expression.
SELECT DATE('2024-01-08 15:30:45');
TIME():
Extracts the time part of a date or datetime expression.
SELECT TIME('2024-01-08 15:30:45');
NOW():
Returns the current date and time.
SELECT NOW();
CURDATE():
This function returns the current date in 'YYYY-MM-DD' format.
SELECT CURDATE();
CURTIME():
This function returns the current time in 'HH:MM:SS' format.
SELECT CURTIME();
CURRENT_TIMESTAMP():
This function returns the current date and time in 'YYYY-MM-DD HH:MM:SS' format.
SELECT CURRENT_TIMESTAMP();
DATE_FORMAT():
Formats a date as specified.
SELECT DATE_FORMAT('2024-01-08', '%W, %M %e, %Y');
DATEDIFF():
Calculates the difference between two dates.
SELECT DATEDIFF('2024-01-15', '2024-01-08');
start_date: '2024-01-08'
INTERVAL: Keyword indicating that you're adding a time interval.
value: The number of intervals to add (5 in this case).
unit: The unit of the interval (DAY in this case).
So, the query adds 5 days to '2024-01-08', resulting in a new date. The output of this query would be:
EXTRACT():
Extracts a part of a date or time.
SELECT EXTRACT(HOUR FROM '2024-01-08 15:30:45');
TIMESTAMPDIFF():
Calculates the difference between two timestamps.
SELECT TIMESTAMPDIFF(SECOND, '2024-01-08 12:00:00', '2024-01-08 15:30:45');
TIMEDIFF():
Calculates the difference between two times.
SELECT TIMEDIFF('15:30:45', '12:00:00');
JOINS
Join in MySQL that allows you to retrieve data from 2 or more tables based on a related column. That related
column is a foreign key that establish a connection between the tables.
The result of a join is a new temporary table that combines column from the tables.
CROSS JOIN
It combines all rows from table 1 with all rows from Table 2.
EMP DEPT
ID NAME DEPT ID EMP_ID SALARY
1 A HR 1 1 50000
2 B IT 2 2 60000
3 C SALES 3 3 45000
Syntax,
SELECT * FROM TABLE1 CROSS JOIN TABLE 2;
INNER JOIN
It retrieves rows where there is a match in both the tables based on a specified condition.
1 A HR 1 1 50000
2 B IT 2 2 60000
3 C SALES 3 3 45000
Syntax,
SELECT * FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.COLUMN
=TABLE2.COLUMN;
OUTER JOIN
Left/left outer join
It retrieves all rows from table1 in matching the rows from table 2. Non matching rows in table
2 will have null values.
EMP DEPT
NAME DEPTNO DNAME DEPTNO
A 20 D1 10
B null D2 20
C 10 D3 30
D null D4 40
A 20 D2
B null null
C 10 D1
D null null
Syntax,
SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON TABLE1.COLUMN
=TABLE2.COLUMN;
RIGHT JOIN
Retrieve all rows from table2 and the matching rows from table1.
Non matching in table1 will have null values.
EMP DEPT
NAME DEPTNO DNAME DEPTNO
A 20 D1 10
B null D2 20
C 10 D3 30
D null D4 40
C 10 D1
A 20 D2
NULL NULL D3
NULL NULL D4
Syntax,
SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON TABLE1.COLUMN
=TABLE2.COLUMN;
-- Employees Table
CREATE TABLE employees (
-> id INT PRIMARY KEY,
-> name VARCHAR(255),
-> department VARCHAR(255)
-> );
-- Salaries Table
CREATE TABLE salaries (
-> id INT PRIMARY KEY,
-> employee_id INT,
-> salary INT,
-> FOREIGN KEY (employee_id) REFERENCES employees(id)
-> );
-- Insert values into Employees table
INSERT INTO employees (id, name, department) VALUES
-> (1, 'Alice', 'HR'),
-> (2, 'Bob', 'IT'),
-> (3, 'Charlie', 'Sales');
-- Inner Join
SELECT employees.id, name, department, salary
-> FROM employees
-> INNER JOIN salaries ON employees.id = salaries.employee_id;