-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheat-sheet.html
59 lines (59 loc) · 2.82 KB
/
cheat-sheet.html
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
<html>
<head>
<title>SQL cheat sheet</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="cheat_sheet_css.css">
</head>
<body>
<header><h1>SQL cheat sheet</h1></header>
<div class="look">
<h2>How to look at tables</h2>
<p class="title">List tables</p>
<p class="text"><b>.tables</b> this will list all active tables in the current session.</p>
<p class="title">List tables and headers</p>
<p class="text"><b>.schema </b>- typing this in will display all active tables.</p>
</div>
<div class="query">
<h2>How to get data from tables</h2>
<p class="title">Selecting</p>
<p class="text"><b>SELECT</b> The SELECT statement is used to select data from a database.
The result is stored in a result table, called the result-set.</p>
<p class="example"> SELECT column_name,column_name
FROM table_name;</p>
<p class="text"><b>ORDER BY</b> The ORDER BY keyword is used to sort the result-set by one or more columns. The ORDER BY keyword sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword.</p>
<p class="example"> SELECT column_name,column_name
FROM table_name
ORDER BY column_name,column_name ASC|DESC;</p>
<p class="title">Wildcards</p>
<p class="text"><b>%</b> A substitute for zero or more characters</p>
<p class="text"><b>_</b> A substitute for a single character</p>
<p class="text"><b>[charlist]</b> Sets and ranges of characters to match</p>
<p class="text"><b>[^charlist] or [!charlist]</b> Matches only a character NOT specified within the brackets</p>
<p class="title">Searching</p>
<p class="text"><b>WHERE</b> The WHERE clause is used to extract only those records that fulfill a specified criterion.</p>
<p class="example"> SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;</p>
<p class="text"><b>LIKE</b> The LIKE operator is used to search for a specified pattern in a column.</p>
<p class="example"> SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;</p>
<p class="text"><b>IN</b> The IN operator allows you to specify multiple values in a WHERE clause.</p>
<p class="example"> SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);</p>
</div>
<div class="manipulate">
<h2>How to manipulate data in tables</h2>
<p class="title">Adding data</p>
<p class="text"><b>INSERT INTO</b> The INSERT INTO statement is used to insert new records in a table.</p>
<p class="example"> INSERT INTO table_name VALUES (value1,value2,value3,...);</p>
<p class="title">Deleting data</p>
<p class="text"><b>DELETE</b> The DELETE statement is used to delete rows in a table.</p>
<p class="example"> DELETE FROM table_name WHERE some_column=some_value;</p>
</div>
</body>
<footer>
List of sources: http://www.w3schools.com/sql/
</footer>
</html>