-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin.html
More file actions
65 lines (50 loc) · 2.85 KB
/
join.html
File metadata and controls
65 lines (50 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!-- SECCIÓN JOIN -->
<div id="join-section">
<div id="adsense-container" style="width: 350px; position: absolute; left: 0px;"></div>
<div class="inner-modal">
<div class="inner" style="padding: 0px;">
<h1>SQL JOIN</h1>
<p>A JOIN clause is used to combine rows from two or more tables, based on a related column (primary,
foreign key) between them.</p>
<h2>INNER JOIN Syntax</h2>
<pre><code class="language-sql">SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name = table2.column_name;</code></pre>
<h2>Example Tables</h2>
<p>Let's look at a selection from the "unit_dose_orders" (outdated) table:</p>
<pre><code class="language-sql">unit_dose_order_id | patient_id | dosage
1 | 9 | 0.25 MG
2 | 15 | 50 MG
3 | 18 | 15</code></pre>
<p>Then, look at a selection from the "patients" table:</p>
<pre><code class="language-sql">patient_id | first_name | last_name
1 | Miyuki | Riviera
2 | Deunan | Knute
3 | Lois | McAllister</code></pre>
<p>Notice that the "patient_id" column in the "unit_dose_orders" table refers to the "patient_id" in the
"patients" table. The relationship between the two tables is the "patient_id" column.</p>
<h2>JOIN Example</h2>
<p>The following SQL statement selects records that have matching values in both tables:</p>
<pre><code class="language-sql">SELECT *
FROM patients p
JOIN admissions a ON a.patient_id = p.patient_id;</code></pre>
<h2>Different Types of SQL JOINs</h2>
<p>It is rare to need a join other than (INNER) JOIN.</p>
<p><strong>DISCLAIMER:</strong> Our tool only supports INNER/LEFT JOIN</p>
<p>Here are the different types of the JOINs in SQL:</p>
<p>- (INNER) JOIN: Returns records that have matching values in both tables</p>
<p>- LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right
table</p>
<p>- RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left
table</p>
<p>- FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table</p>
<img src="joins.png" alt="SQL JOIN Types Diagram" style="max-width: 50%; height: auto; margin: 20px 0;">
<h2>JOIN Three Tables</h2>
<pre><code class="language-sql">SELECT *
FROM patients p
JOIN admissions a ON a.patient_id = p.patient_id
JOIN doctors ph ON ph.doctor_id = a.attending_doctor_id;</code></pre>
</div>
</div>
</div>