From 09ba455ec9c9741e6f852ef1196d057674b1305f Mon Sep 17 00:00:00 2001 From: grishma <74070079+grpatel@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:05:05 -0400 Subject: [PATCH] add crosslinks --- .../02-relational/07-what-are-joins-in-sql.mdx | 13 +++++++------ .../03-joining-tables.mdx | 2 +- .../03-joining-tables.mdx | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/content/03-types/02-relational/07-what-are-joins-in-sql.mdx b/content/03-types/02-relational/07-what-are-joins-in-sql.mdx index 9aa11b5a..99947dbc 100644 --- a/content/03-types/02-relational/07-what-are-joins-in-sql.mdx +++ b/content/03-types/02-relational/07-what-are-joins-in-sql.mdx @@ -14,7 +14,7 @@ JOINs allow you to combine related data from multiple tables in relational datab ## How data is structured in relational databases -Before diving into JOINs, it’s important to understand the fundamentals of relational databases. Relational databases provide a way to structure and organize information. In relational databases, data is structured into _tables_, with _columns_ (attributes) specifying _data types_ (think strings, integers, etc.) and _rows_ containing records (the values for each of the table’s columns). +Before diving into JOINs, it’s important to understand the fundamentals of [relational databases](/intro/database-glossary#relational-database). Relational databases provide a way to structure and organize information. In relational databases, data is structured into _tables_, with _columns_ (attributes) specifying _data types_ (think strings, integers, etc.) and _rows_ containing records (the values for each of the table’s columns). Let’s demonstrate this concept with a table holding customer information. In the table below, the columns, or customer attributes, are `name`, `age`, and `email address` and the rows represent each customer’s `name`, `age`, and `email_address`. @@ -24,7 +24,7 @@ Let’s demonstrate this concept with a table holding customer information. In t | Adrian | 28 | adrian@prisma.io | | Synniva | 25 | synniva@prisma.io | -A relational database has the ability to define relationships, or connections, between different tables using _primary_ and _foreign keys_. +A relational database has the ability to define relationships, or connections, between different tables using [_primary_](/intro/database-glossary#primary-key) and [_foreign keys_](/intro/database-glossary#foreign-key). It is common for tables in a relational database to have a column known as the _primary key_ which uniquely identifies each row. To see how this works in practice, let’s use our previous example: The primary key for the `customers` table would be a column of unique IDs for each customer, called `customer_id`. In other words, no customer would share the same ID as another. @@ -36,7 +36,7 @@ A _foreign key_ is used to create a relationship between tables by referencing t ## What are JOINs? -A useful feature of relational databases is the concept of _JOINs_, a type of SQL operation that combines relevant data from distinct tables often based on the primary and foreign key. +A useful feature of relational databases is the concept of [_JOINs_](/intro/database-glossary#join), a type of SQL operation that combines relevant data from distinct tables often based on the primary and foreign key. The basic syntax of a _JOIN_ operation is as follows: @@ -102,7 +102,7 @@ The most common form of JOIN operations you will encounter are `INNER JOIN`, `LE #### `INNER JOIN` -The `INNER JOIN` is the default JOIN and returns rows from both tables only where there is a match. Here is the associated query for the `customers` and `orders` table: +The [`INNER JOIN`](/intro/database-glossary#inner-join) is the default JOIN and returns rows from both tables only where there is a match. Here is the associated query for the `customers` and `orders` table: ```sql SELECT @@ -127,7 +127,7 @@ When depicted as a Venn diagram, an `INNER JOIN` represents the overlapping regi #### `LEFT JOIN` -A `LEFT JOIN` returns all rows found using the `INNER JOIN` and all records from the first table. Here is the associated query for the `customers` and `orders` table: +A [`LEFT JOIN`](/intro/database-glossary#left-join) returns all rows found using the `INNER JOIN` and all records from the first table. Here is the associated query for the `customers` and `orders` table: ```sql SELECT @@ -153,7 +153,7 @@ When depicted as a Venn diagram, a `LEFT JOIN` represents the entire left circle #### `RIGHT JOIN` -A `RIGHT JOIN` returns all rows found using the `INNER JOIN` and all records from the second table*.* Here is the associated query for the `customers` and `orders` table: +A [`RIGHT JOIN`](/intro/database-glossary#right-join) returns all rows found using the `INNER JOIN` and all records from the second table*.* Here is the associated query for the `customers` and `orders` table: ```sql SELECT @@ -249,6 +249,7 @@ To learn more about database-specific details of JOIN operations, check out thes Lateral JOINs offer a different syntax to combining tables compared to traditional JOINs. In a `LATERAL JOIN`, the second table is presented as a _subquery_, and the JOIN criteria is defined within the `WHERE` clause of the subquery. According to the [PostgreSQL](https://www.postgresql.org/docs/9.3/sql-select.html#SQL-FROM) docs: + > “The `LATERAL` key word can precede a sub-`SELECT FROM` item. This allows the sub-`SELECT` to refer to columns of `FROM` items that appear before it in the `FROM` list. (Without `LATERAL`, each sub-`SELECT` is evaluated independently and so cannot cross-reference any other `FROM` item.)” In other words, a `LATERAL JOIN` is like a foreach loop, where PostgreSQL iterates over each row in a result set and uses each row to evaluate the subquery. diff --git a/content/04-postgresql/13-reading-and-querying-data/03-joining-tables.mdx b/content/04-postgresql/13-reading-and-querying-data/03-joining-tables.mdx index 91d0d374..291c91de 100644 --- a/content/04-postgresql/13-reading-and-querying-data/03-joining-tables.mdx +++ b/content/04-postgresql/13-reading-and-querying-data/03-joining-tables.mdx @@ -10,7 +10,7 @@ authors: ['justinellingwood'] Splitting related data into separate tables can be beneficial from the standpoint of consistency, flexibility, and certain types of performance. However, you still need a reasonable way of reintegrating records when the relevant information spans multiple tables. -In relational databases, _joins_ offer a way to combine the records in two or more tables based on common field values. Different types of joins can achieve different results depending on how unmatched rows should be handled. In this guide, we'll discuss the various types of joins that PostgreSQL offers and how you can use them to combine table data from multiple sources. +In relational databases, [_joins_](/types/relational/what-are-joins-in-sql) offer a way to combine the records in two or more tables based on common field values. Different types of joins can achieve different results depending on how unmatched rows should be handled. In this guide, we'll discuss the various types of joins that PostgreSQL offers and how you can use them to combine table data from multiple sources. ## What are joins? diff --git a/content/05-mysql/10-reading-and-querying-data/03-joining-tables.mdx b/content/05-mysql/10-reading-and-querying-data/03-joining-tables.mdx index b64e3ce4..c419536f 100644 --- a/content/05-mysql/10-reading-and-querying-data/03-joining-tables.mdx +++ b/content/05-mysql/10-reading-and-querying-data/03-joining-tables.mdx @@ -10,7 +10,7 @@ authors: ['justinellingwood'] Though it's often useful to separate data into discrete tables for performance and consistency purposes, you often need to consult data from multiple tables to answer certain requests. _Joining_ tables is a way of combining the data from various tables by matching each record based on common field values. -There are a few different types of joins, which offer various ways of combining table records. In this article, we'll cover how MySQL implements joins and discuss the scenarios in which each is most useful. +There are a few different types of [joins](/types/relational/what-are-joins-in-sql), which offer various ways of combining table records. In this article, we'll cover how MySQL implements joins and discuss the scenarios in which each is most useful. ## What are joins?