|
@@ -41,13 +41,13 @@ Update multiple columns with multiple conditions
|
41
|
41
|
```SQL
|
42
|
42
|
UPDATE people SET birthday = '1955-01-25'
|
43
|
43
|
WHERE
|
44
|
|
- last_name = 'Smith'
|
|
44
|
+ lastName = 'Smith'
|
45
|
45
|
AND id = 4;
|
46
|
46
|
```
|
47
|
47
|
|
48
|
48
|
```SQL
|
49
|
|
-UPDATE people SET mobile = '333-3333', last_name = 'Johnson'
|
50
|
|
-WHERE first_name = 'Noelle' OR first_name = 'Raj';
|
|
49
|
+UPDATE people SET mobile = '333-3333', lastName = 'Johnson'
|
|
50
|
+WHERE firstName = 'Noelle' OR firstName = 'Raj';
|
51
|
51
|
```
|
52
|
52
|
|
53
|
53
|
## Basic Functions
|
|
@@ -69,7 +69,7 @@ SELECT COUNT(*) FROM HOME;
|
69
|
69
|
```
|
70
|
70
|
|
71
|
71
|
```SQL
|
72
|
|
-SELECT COUNT(DISTINCT last_name) FROM PEOPLE;
|
|
72
|
+SELECT COUNT(DISTINCT lastName) FROM PEOPLE;
|
73
|
73
|
```
|
74
|
74
|
|
75
|
75
|
```SQL
|
|
@@ -109,14 +109,14 @@ WHERE LAST_NAME = 'Smith'
|
109
|
109
|
```
|
110
|
110
|
|
111
|
111
|
```SQL
|
112
|
|
-SELECT CONCAT(first_name, ' ', last_name)
|
|
112
|
+SELECT CONCAT(firstName, ' ', lastName)
|
113
|
113
|
FROM people
|
114
|
|
-WHERE last_name = 'Smith'
|
|
114
|
+WHERE lastName = 'Smith'
|
115
|
115
|
```
|
116
|
116
|
|
117
|
117
|
```SQL
|
118
|
|
-SELECT CONCAT_WS(' ',first_name, last_name, mobile)
|
119
|
|
-FROM people WHERE last_name= 'Smith'
|
|
118
|
+SELECT CONCAT_WS(' ',firstName, lastName, mobile)
|
|
119
|
+FROM people WHERE lastName= 'Smith'
|
120
|
120
|
```
|
121
|
121
|
|
122
|
122
|
```SQL
|
|
@@ -142,33 +142,33 @@ SELECT string, LENGTH(string), CHAR_LENGTH(string) FROM length_test
|
142
|
142
|
## Compare
|
143
|
143
|
|
144
|
144
|
```SQL
|
145
|
|
-SELECT first_name, last_name, YEAR(birthday) FROM people WHERE birthday >= '1970-07-06' AND birthday<='1987-07-06';
|
|
145
|
+SELECT firstName, lastName, YEAR(birthday) FROM people WHERE birthday >= '1970-07-06' AND birthday<='1987-07-06';
|
146
|
146
|
```
|
147
|
147
|
|
148
|
148
|
```SQL
|
149
|
|
-SELECT first_name, birthday FROM people WHERE first_name='Thomas' OR first_name='Raj' OR first_name='Sheeri';
|
|
149
|
+SELECT firstName, birthday FROM people WHERE firstName='Thomas' OR firstName='Raj' OR firstName='Sheeri';
|
150
|
150
|
```
|
151
|
151
|
|
152
|
152
|
```SQL
|
153
|
|
-SELECT first_name, birthday FROM people WHERE first_name IN ('Noelle', 'Thomas', 'Raj');
|
|
153
|
+SELECT firstName, birthday FROM people WHERE firstName IN ('Noelle', 'Thomas', 'Raj');
|
154
|
154
|
```
|
155
|
155
|
|
156
|
156
|
#### Wild Cards
|
157
|
157
|
|
158
|
158
|
```SQL
|
159
|
|
-SELECT first_name FROM PEOPLE WHERE RIGHT(first_name,1)='e';
|
|
159
|
+SELECT firstName FROM PEOPLE WHERE RIGHT(firstName,1)='e';
|
160
|
160
|
```
|
161
|
161
|
|
162
|
162
|
```SQL
|
163
|
|
-SELECT first_name FROM people WHERE first_name LIKE '%j';
|
|
163
|
+SELECT firstName FROM people WHERE firstName LIKE '%j';
|
164
|
164
|
```
|
165
|
165
|
|
166
|
166
|
```SQL
|
167
|
|
-SELECT first_name FROM people WHERE first_name LIKE '%o%';
|
|
167
|
+SELECT firstName FROM people WHERE firstName LIKE '%o%';
|
168
|
168
|
```
|
169
|
169
|
|
170
|
170
|
```SQL
|
171
|
|
-SELECT first_name FROM people WHERE first_name NOT LIKE '%o%';
|
|
171
|
+SELECT firstName FROM people WHERE firstName NOT LIKE '%o%';
|
172
|
172
|
```
|
173
|
173
|
|
174
|
174
|
```SQL
|
|
@@ -176,59 +176,59 @@ SELECT COUNT(*) FROM PEOPLE
|
176
|
176
|
```
|
177
|
177
|
|
178
|
178
|
```SQL
|
179
|
|
-SELECT last_name, COUNT(*) FROM people GROUP BY last_name;
|
|
179
|
+SELECT lastName, COUNT(*) FROM people GROUP BY lastName;
|
180
|
180
|
```
|
181
|
181
|
|
182
|
182
|
```SQL
|
183
|
|
-SELECT last_name, GROUP_CONCAT(mobile) FROM PEOPLE GROUP BY last_name;
|
|
183
|
+SELECT lastName, GROUP_CONCAT(mobile) FROM PEOPLE GROUP BY lastName;
|
184
|
184
|
```
|
185
|
185
|
|
186
|
186
|
```SQL
|
187
|
|
-SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY last_name;
|
|
187
|
+SELECT lastName, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY lastName;
|
188
|
188
|
```
|
189
|
189
|
|
190
|
190
|
```SQL
|
191
|
|
-SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY last_name HAVING COUNT(*)>1;
|
|
191
|
+SELECT lastName, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY lastName HAVING COUNT(*)>1;
|
192
|
192
|
```
|
193
|
193
|
|
194
|
194
|
```SQL
|
195
|
|
-SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people WHERE last_name != 'Cabral' GROUP BY last_name HAVING COUNT(*)>1;
|
|
195
|
+SELECT lastName, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people WHERE lastName != 'Cabral' GROUP BY lastName HAVING COUNT(*)>1;
|
196
|
196
|
```
|
197
|
197
|
|
198
|
198
|
#### Sorting
|
199
|
199
|
|
200
|
200
|
```SQL
|
201
|
|
-SELECT first_name, birthday FROM people ORDER BY birthday;
|
|
201
|
+SELECT firstName, birthday FROM people ORDER BY birthday;
|
202
|
202
|
```
|
203
|
203
|
|
204
|
204
|
```SQL
|
205
|
|
-SELECT first_name, birthday FROM people ORDER BY birthday DESC;
|
|
205
|
+SELECT firstName, birthday FROM people ORDER BY birthday DESC;
|
206
|
206
|
```
|
207
|
207
|
|
208
|
208
|
```SQL
|
209
|
|
-SELECT first_name, last_name FROM people ORDER BY last_name, first_name;
|
|
209
|
+SELECT firstName, lastName FROM people ORDER BY lastName, firstName;
|
210
|
210
|
```
|
211
|
211
|
|
212
|
212
|
```SQL
|
213
|
|
-SELECT first_name, birthday FROM people ORDER BY birthday DESC LIMIT 3;
|
|
213
|
+SELECT firstName, birthday FROM people ORDER BY birthday DESC LIMIT 3;
|
214
|
214
|
```
|
215
|
215
|
|
216
|
216
|
```SQL
|
217
|
|
-SELECT first_name, MONTHNAME(birthday) as mon, birthday FROM people ORDER BY MONTH(birthday);
|
|
217
|
+SELECT firstName, MONTHNAME(birthday) as mon, birthday FROM people ORDER BY MONTH(birthday);
|
218
|
218
|
```
|
219
|
219
|
|
220
|
220
|
```SQL
|
221
|
|
-SELECT last_name, COUNT(*) FROM people GROUP BY last_name;
|
|
221
|
+SELECT lastName, COUNT(*) FROM people GROUP BY lastName;
|
222
|
222
|
```
|
223
|
223
|
|
224
|
224
|
```SQL
|
225
|
|
-SELECT last_name, COUNT(*) FROM people GROUP BY last_name ORDER BY NULL;
|
|
225
|
+SELECT lastName, COUNT(*) FROM people GROUP BY lastName ORDER BY NULL;
|
226
|
226
|
```
|
227
|
227
|
|
228
|
228
|
## Inserting and Replacing Records
|
229
|
229
|
|
230
|
230
|
```SQL
|
231
|
|
-INSERT INTO people (first_name, last_name, birthday, home_id)
|
|
231
|
+INSERT INTO people (firstName, lastName, birthday, home_id)
|
232
|
232
|
VALUES
|
233
|
233
|
('John', 'Smith', '1998-04-07', 4),
|
234
|
234
|
('Maya', 'Wasserman' , NULL, 4),
|
|
@@ -238,7 +238,7 @@ INSERT INTO people (first_name, last_name, birthday, home_id)
|
238
|
238
|
#### Replace
|
239
|
239
|
|
240
|
240
|
```SQL
|
241
|
|
-DELETE FROM people WHERE first_name='Maya';
|
|
241
|
+DELETE FROM people WHERE firstName='Maya';
|
242
|
242
|
```
|
243
|
243
|
|
244
|
244
|
```SQL
|
|
@@ -246,7 +246,7 @@ SELECT * FROM people;
|
246
|
246
|
```
|
247
|
247
|
|
248
|
248
|
```SQL
|
249
|
|
-MERGE INTO people (first_name, last_name, birthday, home_id)
|
|
249
|
+MERGE INTO people (firstName, lastName, birthday, home_id)
|
250
|
250
|
VALUES
|
251
|
251
|
('John', 'Sharma', '1998-04-07', 1),
|
252
|
252
|
('Paul', 'Sharma', '1996-05-27', 4),
|
|
@@ -257,7 +257,7 @@ MERGE INTO people (first_name, last_name, birthday, home_id)
|
257
|
257
|
## JOIN
|
258
|
258
|
|
259
|
259
|
```SQL
|
260
|
|
-INSERT INTO people (first_name, last_name, birthday)
|
|
260
|
+INSERT INTO people (firstName, lastName, birthday)
|
261
|
261
|
VALUES ('Eli', 'Kramer', '1984-01-15');
|
262
|
262
|
```
|
263
|
263
|
|
|
@@ -271,13 +271,13 @@ SELECT * FROM home;
|
271
|
271
|
```
|
272
|
272
|
|
273
|
273
|
```SQL
|
274
|
|
-SELECT p.first_name, h.address
|
|
274
|
+SELECT p.firstName, h.address
|
275
|
275
|
FROM PEOPLE p
|
276
|
276
|
INNER JOIN HOME h on (p.HOME_ID = h.ID)
|
277
|
277
|
```
|
278
|
278
|
|
279
|
279
|
```SQL
|
280
|
|
-SELECT first_name, last_name
|
|
280
|
+SELECT firstName, lastName
|
281
|
281
|
FROM PEOPLE p
|
282
|
282
|
INNER JOIN HOME h on (p.HOME_ID = h.HOME_ID)
|
283
|
283
|
WHERE p.HOME_ID = 1
|
|
@@ -287,7 +287,7 @@ WHERE p.HOME_ID = 1
|
287
|
287
|
SELECT p.*, h.address, h.homenumber
|
288
|
288
|
FROM PEOPLE p
|
289
|
289
|
INNER JOIN HOME h on (p.HOME_ID = h.HOME_ID)
|
290
|
|
-WHERE p.first_name LIKE '%e%'
|
|
290
|
+WHERE p.firstName LIKE '%e%'
|
291
|
291
|
```
|
292
|
292
|
|
293
|
293
|
##### Exercise:
|