An INNER JOIN is a term used in SQL (Structured Query Language) to combine rows from two (or more) tables based on a related column between them.
You have two tables:
Table: Customers
CustomerID | Name |
---|---|
1 | Anna |
2 | Bernd |
3 | Clara |
Table: Orders
OrderID | CustomerID | Product |
---|---|---|
101 | 1 | Book |
102 | 2 | Laptop |
103 | 4 | Phone |
Now you want to know which customers have placed orders. You only want the customers who exist in both tables.
SELECT Customers.Name, Orders.Product
FROM Customers
INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
Name | Product |
---|---|
Anna | Book |
Bernd | Laptop |
Clara didn’t place any orders → not included.
The order with CustomerID 4 doesn’t match any customer → also excluded.
An INNER JOIN returns only the rows with matching values in both tables.
An explicit join is a clear and direct way to define a join in an SQL query, where the type of join (such as INNER JOIN
, LEFT JOIN
, RIGHT JOIN
, or FULL OUTER JOIN
) is explicitly stated.
SELECT *
FROM customers
INNER JOIN orders
ON customers.customer_id = orders.customer_id;
This makes it clear:
Which tables are being joined (customers
, orders
)
What kind of join is used (INNER JOIN
)
What the join condition is (ON customers.customer_id = orders.customer_id
)
An implicit join is the older style, using a comma in the FROM
clause, and putting the join condition in the WHERE
clause:
SELECT *
FROM customers, orders
WHERE customers.customer_id = orders.customer_id;
This works the same, but it's less clear and not ideal for complex queries.
More readable and structured, especially with multiple tables
Clear separation of join conditions (ON
) and filter conditions (WHERE
)
Recommended in modern SQL development
An implicit join is a way of joining tables in SQL without using the JOIN
keyword explicitly. Instead, the join is expressed using the WHERE
clause.
SELECT *
FROM customers, orders
WHERE customers.customer_id = orders.customer_id;
In this example, the tables customers
and orders
are joined using a condition in the WHERE
clause.
SELECT *
FROM customers
JOIN orders ON customers.customer_id = orders.customer_id;
Aspect | Implicit Join | Explicit Join |
---|---|---|
Syntax | Tables separated by commas, joined via WHERE |
Uses JOIN and ON |
Readability | Less readable in complex queries | More structured and readable |
Error-proneness | Higher (e.g., accidental cross joins) | Lower, as join conditions are clearer |
ANSI-92 compliance | Not compliant | Fully compliant |
It was common in older SQL code, but explicit joins are recommended today, as they are clearer, easier to maintain, and less error-prone, especially in complex queries involving multiple tables.
A Materialized View is a special type of database object that stores the result of a SQL query physically on disk, unlike a regular view which is computed dynamically every time it’s queried.
Stored on disk: The result of the query is saved, not just the query definition.
Faster performance: Since the data is precomputed, queries against it are typically much faster.
Needs refreshing: Because the underlying data can change, a materialized view must be explicitly or automatically refreshed to stay up to date.
Feature | View | Materialized View |
---|---|---|
Storage | Only the query, no data stored | Query and data are stored |
Performance | Slower for complex queries | Faster, as results are precomputed |
Freshness | Always up to date | Can become stale |
Needs refresh | No | Yes (manually or automatically) |
-- Creating a materialized view in PostgreSQL
CREATE MATERIALIZED VIEW top_customers AS
SELECT customer_id, SUM(order_total) AS total_spent
FROM orders
GROUP BY customer_id;
To refresh the data:
REFRESH MATERIALIZED VIEW top_customers;
For complex aggregations that are queried frequently
When performance is more important than real-time accuracy
In data warehouses or reporting systems
MariaDB is a relational database management system (RDBMS) developed as an open-source alternative to MySQL. It was created in 2009 by the original MySQL developers after MySQL was acquired by Oracle. The goal was to provide a fully open, compatible version of MySQL that remains independent.
MySQL Compatibility:
Enhanced Features:
Active Development:
MariaDB is a powerful and flexible database solution, highly valued for its openness, security, and compatibility with MySQL. It is an excellent choice for developers and organizations looking for a reliable open-source database.
An object-oriented database management system (OODBMS) is a type of database system that combines the principles of object-oriented programming (OOP) with the functionality of a database. It allows data to be stored, retrieved, and managed as objects, similar to how they are defined in object-oriented programming languages like Java, Python, or C++.
Object Model:
Classes and Inheritance:
Encapsulation:
Persistence:
Object Identity (OID):
Complex Data Types:
Object-oriented databases are particularly useful for managing complex, hierarchical, or nested data structures commonly found in modern software applications.
Object Query Language (OQL) is a query language similar to SQL (Structured Query Language) but specifically designed for object-oriented databases. It is used to query data from object-oriented database systems (OODBs), which store data as objects. OQL was defined as part of the Object Data Management Group (ODMG) standard.
Object-Oriented Focus:
SQL-Like Syntax:
Querying Complex Objects:
Support for Methods:
Integration with Object-Oriented Languages:
Suppose there is a database with a class Person
that has the attributes Name
and Age
. An OQL query might look like this:
SELECT p.Name
FROM Person p
WHERE p.Age > 30
This query retrieves the names of all people whose age is greater than 30.
In practice, OQL is less popular than SQL since relational databases are still dominant. However, OQL is very powerful in specialized applications that utilize object-oriented data models.
Data Definition Language (DDL) is a part of SQL (Structured Query Language) that deals with defining and managing the structure of a database. DDL commands modify the metadata of a database, such as information about tables, schemas, indexes, and other database objects, rather than manipulating the actual data.
1. CREATE
Used to create new database objects like tables, schemas, views, or indexes.
Example:
CREATE TABLE Kunden (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Alter INT
);
2. ALTER
Used to modify the structure of existing objects, such as adding or removing columns.
Example:
ALTER TABLE Kunden ADD Email VARCHAR(100);
3. DROP
Permanently deletes a database object, such as a table.
Example:
DROP TABLE Kunden;
4. TRUNCATE
Removes all data from a table while keeping its structure intact. It is faster than DELETE
as it does not generate transaction logs.
Example:
TRUNCATE TABLE Kunden;
DDL is essential for designing and managing a database and is typically used during the initial setup or when structural changes are required.
A Character Large Object (CLOB) is a data type used in database systems to store large amounts of text data. The term stands for "Character Large Object." CLOBs are particularly suitable for storing texts like documents, HTML content, or other extensive strings that exceed the storage capacity of standard text fields.
TEXT
types, which function similarly to CLOBs.TEXT
or specialized data types.
ACID is an acronym that describes four key properties essential for the reliability of database transactions in a database management system (DBMS). These properties ensure the integrity of data and the consistency of the database even in the event of errors or system crashes. ACID stands for:
Atomicity:
Consistency:
Isolation:
Durability:
Consider a bank database with two accounts: Account A and Account B. A transaction transfers 100 euros from Account A to Account B. The ACID properties ensure the following:
The ACID properties are crucial for the reliability and integrity of database transactions, especially in systems dealing with sensitive data, such as financial institutions, e-commerce platforms, and critical business applications. They help prevent data loss and corruption, ensuring that data remains consistent and trustworthy.