Database Management System (DBMS) Part-2
Foreign key in DBMS:
A foreign key in DBMS (Database Management System) is a field (or a set of fields) in one table that refers to the PRIMARY KEY of another table.
It is used to establish a relationship between two tables and ensures referential integrity—meaning the database prevents actions that would leave broken links between related tables. Learn More
Order of different clauses in MYSQL:
Here is an example using a hypothetical Orders table with columns like CustomerID, ProductID, and Quantity to illustrate the order of clauses:
We want to find customers who placed more than 5 orders total, but only count orders placed after January 1, 2024, and then display the results sorted by the total quantity in descending order.
SELECT
CustomerID,
SUM(Quantity) AS TotalQuantity
FROM
Orders
WHERE
OrderDate > '2024-01-01'
GROUP BY
CustomerID
HAVING
COUNT(OrderID) > 5
ORDER BY
TotalQuantity DESC;