-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhere.html
More file actions
75 lines (57 loc) · 2.83 KB
/
where.html
File metadata and controls
75 lines (57 loc) · 2.83 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
66
67
68
69
70
71
72
73
74
75
<!-- SECCIÓN WHERE -->
<div id="where-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 WHERE Clause</h1>
<p>The WHERE clause is used to filter records.</p>
<p>It is used to extract only those records that fulfill a specified condition.</p>
<h2>WHERE Syntax</h2>
<pre><code class="language-sql">SELECT column1, column2, ...
FROM tablename
WHERE condition;</code></pre>
<h2>WHERE Clause Example</h2>
<p>The following SQL statement selects all the patients with the gender "F", in the "patients" table:</p>
<pre><code class="language-sql">SELECT * FROM patients
WHERE gender = 'F';</code></pre>
<h2>Text Fields vs. Numeric Fields</h2>
<p>SQL requires single quotes around text values (most database systems will also allow double quotes).</p>
<p>However, numeric fields should not be enclosed in quotes:</p>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id = 1;</code></pre>
<h2>Operators</h2>
<p>The following operators can be used in the WHERE clause:</p>
<h3>Equal (=)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id = 1;</code></pre>
<h3>Greater Than (>)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id > 5;</code></pre>
<h3>Less Than (<)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id < 5;</code></pre>
<h3>Greater Than Or Equal To (>=)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id >= 5;</code></pre>
<h3>Less Than Or Equal To (<=)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id <= 5;</code></pre>
<h3>Not Equal (<> or !=)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id <> 5;
-- No patient_id 5 row</code></pre>
<h3>Between (inclusive range)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id BETWEEN 4 AND 6;</code></pre>
<h3>Like (pattern search)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE first_name LIKE 'a%';
-- First names starting with 'a'.
-- View sql patterns for more info.</code></pre>
<h3>IN (in a collection)</h3>
<pre><code class="language-sql">SELECT * FROM patients
WHERE patient_id IN (1, 3, 6, 9);
-- the values can be replaced with a sub-query.</code></pre>
</div>
</div>
</div>