├── README.md
├── comments.sql
├── databases.sql
├── db-hr.sql
├── db-inventory.sql
├── db-invoicing.sql
├── db-store.sql
├── facebook_users.sql
├── full database.sql
├── posts.sql
├── products.sql
├── test.sql
└── users.sql
/README.md:
--------------------------------------------------------------------------------
1 | # `Complete-SQL`
2 |
3 | ## Table of Contents 📋
4 | | **SNo.** | **Topic** | **Sub Topic** |
5 | | -------- | --------- | ------------- |
6 | | 1. | [Retrieving Data From a Single Table](#1-retrieving-data-from-a-single-table) | [SELECT Clause](#11-select-clause)
[WHERE Clause](#12-where-clause)
[AND, OR & NOT Operators](#13-and-or--not-operators)
[IN Operators](#14-in-operators)
[BETWEEN Operators](#15-between-operators)
[LIKE Operators](#16-like-operators)
[REGEXP Operators](#17-regexp-operators)
[IS NULL Operators](#18-is-null-operators)
[ORDER BY Operators](#19-order-by-operators)
[LIMIT Clause](#110-limit-clause)|
7 | | 2. | [Retrieving Data From a Multiple Table](#2-retrieving-data-from-a-multiple-table) | [INNER Joins](#21-inner-joins)
[Joining Across Databases](#22-joining-across-databases)
[Self Joins](#23-self-joins)
[Joining Multiple Tables](#24-joining-multiple-tables)
[Compound Join Conditions](#25-compound-join-conditions)
[Implicit Join Syntax](#26-implicit-join-syntax)
[OUTER Joins](#27-outer-joins)
[Outer Join Between Multiple Tables](#28-outer-join-between-multiple-tables)
[Self Outer Joins](#29-self-outer-joins)
[The USING Clause](#210-the-using-clause)
[NATURAL Joins](#211-natural-joins)
[CROSS Joins](#212-cross-joins)
[UNIONS](#213-unions)|
8 | | 3. | [Inserting, Updating, and Deleting Data](#3-inserting-updating-and-deleting-data) | |
9 |
10 | ---
11 |
12 | ## 1. Retrieving Data From a Single Table
13 | - ### 1.1 SELECT Clause
14 | ```sql
15 | SELECT *
16 | FROM customers;
17 | ```
18 | | customer_id| first_name | last_name | points | state | phone_no | birth_date |
19 | |-------------|-----------|-----------|--------|-------|----------|------------|
20 | | | | | | | | |
21 | | | | | | | | |
22 |
23 | ```sql
24 | SELECT first_name, last_name
25 | FROM customers;
26 | ```
27 | | first_name | last_name |
28 | |------------|-----------|
29 | | | |
30 | | | |
31 |
32 | ```sql
33 | SELECT
34 | first_name,
35 | last_name,
36 | points,
37 | (points % 10) AS 'discount factor'
38 | FROM customers;
39 | ```
40 |
41 | | first_name | last_name | points | discount factor |
42 | |------------|-----------|--------|-----------------|
43 | | | | | |
44 | | | | | |
45 |
46 | `Exercise`
47 | - Return All the Products
48 | - name
49 | - unit price
50 | - new price (unit price * 1.1)
51 |
52 | `Solution`
53 | ```sql
54 | SELECT
55 | name,
56 | unit_price,
57 | (unit_price * 1.1) AS new_price
58 | FROM products;
59 | ```
60 |
61 | | name | unit_price | new_price |
62 | |------|------------|-----------|
63 | | | | |
64 | | | | |
65 |
66 | - ## 1.2 WHERE Clause
67 | ```sql
68 | SELECT *
69 | FROM customers
70 | WHERE points > 3000;
71 | ```
72 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
73 | |-------------|------------|-----------|--------|-------|----------|------------|
74 | | | | | | | | |
75 | | | | | | | | |
76 |
77 | ```sql
78 | SELECT *
79 | FROM customers
80 | WHERE state = 'va';
81 | ```
82 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
83 | |-------------|------------|-----------|--------|-------|----------|------------|
84 | | | | | | | | |
85 | | | | | | | | |
86 |
87 | ```sql
88 | SELECT *
89 | FROM customers
90 | WHERE birth_date > '1990-01-01';
91 | ```
92 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
93 | |-------------|------------|-----------|--------|-------|----------|------------|
94 | | | | | | | | |
95 | | | | | | | | |
96 |
97 | `Exercise`
98 | - Get the orders places this years
99 |
100 | `Solution`
101 | ```sql
102 | SELECT *
103 | FROM orders
104 | WHERE order_date >= '2022-01-01';
105 | ```
106 | | order_id | customer_id | first_name | last_name | points | status | order_date |
107 | |----------|-------------|------------|-----------|--------|--------|------------|
108 | | | | | | | | |
109 | | | | | | | | |
110 |
111 | - ### 1.3 AND, OR & NOT Operators
112 | ```sql
113 | SELECT *
114 | FROM customers
115 | WHERE birth_date > '1990-01-01' AND points > 1000;
116 | ```
117 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
118 | |-------------|------------|-----------|--------|-------|----------|------------|
119 | | | | | | | | |
120 | | | | | | | | |
121 |
122 | ```sql
123 | SELECT *
124 | FROM customers
125 | WHERE birth_date > '1990-01-01' OR points > 1000 AND state = 'va';
126 | ```
127 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
128 | |-------------|------------|-----------|--------|-------|----------|------------|
129 | | | | | | | | |
130 | | | | | | | | |
131 |
132 | ```sql
133 | SELECT *
134 | FROM customers
135 | WHERE NOT (birth_date > '1990-01-01' OR points > 1000);
136 | ```
137 | ```sql
138 | SELECT *
139 | FROM customers
140 | WHERE birth_date <= '1990-01-01' AND points <= 1000;
141 | ```
142 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
143 | |-------------|------------|-----------|--------|-------|----------|------------|
144 | | | | | | | | |
145 | | | | | | | | |
146 |
147 | `Exercise`
148 | - From the order_items table, get the item
149 | - For order #6
150 | - where the total price is greater than 30
151 |
152 | `Solution`
153 | ```sql
154 | SELECT *
155 | FROM order_items
156 | WHERE order_id = 6 AND unit_price * quantity > 30;
157 | ```
158 | | order_id | product_id | unit_price | quantity | order_item |
159 | |----------|------------|------------|----------|------------|
160 | | | | | | |
161 | | | | | | |
162 |
163 | - ### 1.4 IN Operators
164 | ```sql
165 | SELECT *
166 | FROM customers
167 | WHERE state = 'va' OR state = 'ga' OR state = 'fl';
168 | ```
169 | ```sql
170 | SELECT *
171 | FROM customers
172 | WHERE state IN ('va', 'ga', 'fl');
173 | ```
174 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
175 | |-------------|------------|-----------|--------|-------|----------|------------|
176 | | | | | | | | |
177 | | | | | | | | |
178 |
179 | ```sql
180 | SELECT *
181 | FROM customers
182 | WHERE state NOT IN ('va', 'ga', 'fl');
183 | ```
184 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
185 | |-------------|------------|-----------|--------|-------|----------|------------|
186 | | | | | | | | |
187 | | | | | | | | |
188 |
189 | `Exercise`
190 | - Return products with
191 | - quantity in stock equal to 49, 38, 72
192 |
193 | `Solution`
194 | ```sql
195 | SELECT *
196 | FROM products
197 | WHERE quantity_in_stock IN (49, 38, 72);
198 | ```
199 | | order_id | product_id | unit_price | quantity_in_stocks | order_item |
200 | |----------|------------|------------|--------------------|------------|
201 | | | | | | |
202 | | | | | | |
203 |
204 | - ### 1.5 BETWEEN Operators
205 | ```sql
206 | SELECT *
207 | FROM customers
208 | WHERE points >= 1000 AND points <= 3000;
209 | ```
210 | ```sql
211 | SELECT *
212 | FROM customers
213 | WHERE points BETWEEN 1000 AND 3000;
214 | ```
215 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
216 | |-------------|------------|-----------|--------|-------|----------|------------|
217 | | | | | | | | |
218 | | | | | | | | |
219 |
220 | `Exercise`
221 | - Return customers born
222 | - between 1/1/1990 AND 1/1/2000
223 |
224 | `Solution`
225 | ```sql
226 | SELECT *
227 | FROM customers
228 | WHERE birth_date BETWEEN '1990-01-01` AND `2000-01-01`;
229 | ```
230 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
231 | |-------------|------------|-----------|--------|-------|----------|------------|
232 | | | | | | | | |
233 | | | | | | | | |
234 |
235 | - ### 1.6 LIKE Operators
236 | - `% -----> Any number of characters`
237 | - `_ -----> Single Character`
238 | ```sql
239 | SELECT *
240 | FROM customers
241 | WHERE last_name LIKE 'b%';
242 | ```
243 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
244 | |-------------|------------|-----------|--------|-------|----------|------------|
245 | | | | | | | | |
246 | | | | | | | | |
247 |
248 | ```sql
249 | SELECT *
250 | FROM customers
251 | WHERE last_name LIKE 'brush%';
252 | ```
253 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
254 | |-------------|------------|-----------|--------|-------|----------|------------|
255 | | | | | | | | |
256 | | | | | | | | |
257 |
258 | ```sql
259 | SELECT *
260 | FROM customers
261 | WHERE last_name LIKE '%b%';
262 | ```
263 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
264 | |-------------|------------|-----------|--------|-------|----------|------------|
265 | | | | | | | | |
266 | | | | | | | | |
267 |
268 | ```sql
269 | SELECT *
270 | FROM customers
271 | WHERE last_name LIKE '%y';
272 | ```
273 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
274 | |-------------|------------|-----------|--------|-------|----------|------------|
275 | | | | | | | | |
276 | | | | | | | | |
277 |
278 | ```sql
279 | SELECT *
280 | FROM customers
281 | WHERE last_name LIKE '_y';
282 | ```
283 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
284 | |-------------|------------|-----------|--------|-------|----------|------------|
285 | | | | | | | | |
286 | | | | | | | | |
287 |
288 | ```sql
289 | SELECT *
290 | FROM customers
291 | WHERE last_name LIKE '_______y';
292 | ```
293 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
294 | |-------------|------------|-----------|--------|-------|----------|------------|
295 | | | | | | | | |
296 | | | | | | | | |
297 |
298 | ```sql
299 | SELECT *
300 | FROM customers
301 | WHERE last_name LIKE 'b_______y';
302 | ```
303 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
304 | |-------------|------------|-----------|--------|-------|----------|------------|
305 | | | | | | | | |
306 | | | | | | | | |
307 |
308 | `Exercise`
309 | - Get the customers whose
310 | - addresses contain TRAIL or AVENUE
311 | - phone number end with 9
312 |
313 | `Solution`
314 |
315 | - `addresses contain TRAIL or AVENUE`
316 | ```sql
317 | SELECT *
318 | FROM customers
319 | WHERE
320 | address LIKE '%trail%' OR
321 | address LIKE '%avenue%';
322 | ```
323 | | customer_id | first_name | last_name | points | address | phone_no | birth_date |
324 | |-------------|------------|-----------|--------|---------|----------|------------|
325 | | | | | | | | |
326 | | | | | | | | |
327 |
328 | - `phone number end with 9`
329 | ```sql
330 | SELECT *
331 | FROM customers
332 | WHERE phone_no LIKE '%9';
333 | ```
334 | | customer_id | first_name | last_name | points | address | phone_no | birth_date |
335 | |-------------|------------|-----------|--------|---------|----------|------------|
336 | | | | | | | | |
337 | | | | | | | | |
338 |
339 | - ### 1.7 REGEXP Operators
340 | - `^ -----> beginning`
341 | - `$ -----> end`
342 | - `| -----> logical or`
343 | - `[gim]e -----> ge, ie, me`
344 | - `e[faq] -----> ef, ea, eq`
345 | - `[a-f]g -----> ag, bg, cg, dg, eg, fg`
346 | ```sql
347 | SELECT *
348 | FROM customers
349 | WHERE last_name LIKE '%brush%';
350 | ```
351 | ```sql
352 | SELECT *
353 | FROM customers
354 | WHERE last_name REGEXP 'brush';
355 | ```
356 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
357 | |-------------|------------|-----------|--------|-------|----------|------------|
358 | | | | | | | | |
359 | | | | | | | | |
360 |
361 | ```sql
362 | SELECT *
363 | FROM customers
364 | WHERE last_name REGEXP '^brush';
365 | ```
366 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
367 | |-------------|------------|-----------|--------|-------|----------|------------|
368 | | | | | | | | |
369 | | | | | | | | |
370 |
371 | ```sql
372 | SELECT *
373 | FROM customers
374 | WHERE last_name REGEXP 'brush$';
375 | ```
376 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
377 | |-------------|------------|-----------|--------|-------|----------|------------|
378 | | | | | | | | |
379 | | | | | | | | |
380 |
381 | ```sql
382 | SELECT *
383 | FROM customers
384 | WHERE last_name REGEXP 'brush|mac';
385 | ```
386 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
387 | |-------------|------------|-----------|--------|-------|----------|------------|
388 | | | | | | | | |
389 | | | | | | | | |
390 |
391 | ```sql
392 | SELECT *
393 | FROM customers
394 | WHERE last_name REGEXP 'brush|mac|field';
395 | ```
396 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
397 | |-------------|------------|-----------|--------|-------|----------|------------|
398 | | | | | | | | |
399 | | | | | | | | |
400 |
401 | ```sql
402 | SELECT *
403 | FROM customers
404 | WHERE last_name REGEXP '^brush|mac|field';
405 | ```
406 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
407 | |-------------|------------|-----------|--------|-------|----------|------------|
408 | | | | | | | | |
409 | | | | | | | | |
410 |
411 | ```sql
412 | SELECT *
413 | FROM customers
414 | WHERE last_name REGEXP 'brush$|mac|field';
415 | ```
416 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
417 | |-------------|------------|-----------|--------|-------|----------|------------|
418 | | | | | | | | |
419 | | | | | | | | |
420 |
421 | ```sql
422 | SELECT *
423 | FROM customers
424 | WHERE last_name REGEXP '[gim]e';
425 | ```
426 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
427 | |-------------|------------|-----------|--------|-------|----------|------------|
428 | | | | | | | | |
429 | | | | | | | | |
430 |
431 | ```sql
432 | SELECT *
433 | FROM customers
434 | WHERE last_name REGEXP 'e[abc]';
435 | ```
436 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
437 | |-------------|------------|-----------|--------|-------|----------|------------|
438 | | | | | | | | |
439 | | | | | | | | |
440 |
441 | ```sql
442 | SELECT *
443 | FROM customers
444 | WHERE last_name REGEXP '[a-h]e';
445 | ```
446 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
447 | |-------------|------------|-----------|--------|-------|----------|------------|
448 | | | | | | | | |
449 | | | | | | | | |
450 |
451 | `Exercise`
452 | - Get the customers whose
453 | - first names are ELKA or AMAR
454 | - last names end with EY or ON
455 | - last names start with MY or contains SE
456 | - last names contain B followed by R or U
457 |
458 | `Solution`
459 | - `first names are ELKA or AMAR`
460 | ```sql
461 | SELECT *
462 | FROM customers
463 | WHERE first_name REGEXP 'elka | amar';
464 | ```
465 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
466 | |-------------|------------|-----------|--------|-------|----------|------------|
467 | | | | | | | | |
468 | | | | | | | | |
469 |
470 | - `last names end with EY or ON`
471 | ```sql
472 | SELECT *
473 | FROM customers
474 | WHERE last_name REGEXP 'ey$ | on$';
475 | ```
476 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
477 | |-------------|------------|-----------|--------|-------|----------|------------|
478 | | | | | | | | |
479 | | | | | | | | |
480 |
481 | - `last names start with MY or contains SE`
482 | ```sql
483 | SELECT *
484 | FROM customers
485 | WHERE last_name REGEXP '^my | se';
486 | ```
487 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
488 | |-------------|------------|-----------|--------|-------|----------|------------|
489 | | | | | | | | |
490 | | | | | | | | |
491 |
492 | - `last names contain B followed by R or U`
493 | ```sql
494 | SELECT *
495 | FROM customers
496 | WHERE last_name REGEXP 'b[ru]';
497 | ```
498 | ```sql
499 | SELECT *
500 | FROM customers
501 | WHERE last_name REGEXP 'br | bu';
502 | ```
503 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
504 | |-------------|------------|-----------|--------|-------|----------|------------|
505 | | | | | | | | |
506 | | | | | | | | |
507 |
508 | - ### 1.8 IS NULL Operators
509 | ```sql
510 | SELECT *
511 | FROM customers
512 | WHERE phone_no IS NULL;
513 | ```
514 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
515 | |-------------|------------|-----------|--------|-------|----------|------------|
516 | | | | | | | | |
517 | | | | | | | | |
518 |
519 | ```sql
520 | SELECT *
521 | FROM customers
522 | WHERE phone_no IS NOT NULL;
523 | ```
524 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
525 | |-------------|------------|-----------|--------|-------|----------|------------|
526 | | | | | | | | |
527 | | | | | | | | |
528 |
529 | `Exercise`
530 | - Get the orders that are not shipped
531 |
532 | `Solution`
533 | ```sql
534 | SELECT *
535 | FROM orders
536 | WHERE shipped_date IS NULL;
537 | ```
538 | | order_id | customer_id | first_name | last_name | points | status | shipped_date | order_date |
539 | |----------|-------------|------------|-----------|--------|--------|--------------|------------|
540 | | | | | | | | | |
541 | | | | | | | | | |
542 |
543 | - ### 1.9 ORDER BY Operators
544 | ```sql
545 | SELECT *
546 | FROM customers
547 | ORDER BY first_name;
548 | ```
549 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
550 | |-------------|------------|-----------|--------|-------|----------|------------|
551 | | | | | | | | |
552 | | | | | | | | |
553 |
554 | ```sql
555 | SELECT *
556 | FROM customers
557 | ORDER BY first_name DESC;
558 | ```
559 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
560 | |-------------|------------|-----------|--------|-------|----------|------------|
561 | | | | | | | | |
562 | | | | | | | | |
563 |
564 | ```sql
565 | SELECT *
566 | FROM customers
567 | ORDER BY first_name, state;
568 | ```
569 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
570 | |-------------|------------|-----------|--------|-------|----------|------------|
571 | | | | | | | | |
572 | | | | | | | | |
573 |
574 | ```sql
575 | SELECT *
576 | FROM customers
577 | ORDER BY first_name DESC, state DESC;
578 | ```
579 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
580 | |-------------|------------|-----------|--------|-------|----------|------------|
581 | | | | | | | | |
582 | | | | | | | | |
583 |
584 | ```sql
585 | SELECT first_name, last_name
586 | FROM customers
587 | ORDER BY birth_date;
588 | ```
589 | |first_name | last_name |
590 | |------------|-----------|
591 | | | |
592 | | | |
593 |
594 | ```sql
595 | SELECT first_name, last_name, 10 AS points
596 | FROM customers
597 | ORDER BY first_name, points;
598 | ```
599 | ```sql
600 | SELECT first_name, last_name, 10 AS points
601 | FROM customers
602 | ORDER BY 1, 3;
603 | ```
604 | |first_name | last_name | points |
605 | |------------|-----------|--------|
606 | | | | |
607 | | | | |
608 |
609 | - ### 1.10 LIMIT Clause
610 | - `LIMIT 6 -----> print first 6 rows(1, 2, 3, 4, 5, 6)`
611 | - `LIMIT 6, 3 -----> Skip first 6 rows(1, 2, 3, 4, 5, 6) then print 3 rows(7, 8, 9)`
612 |
613 | ```sql
614 | SELECT *
615 | FROM customers
616 | LIMIT 6;
617 | ```
618 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
619 | |-------------|------------|-----------|--------|-------|----------|------------|
620 | | | | | | | | |
621 | | | | | | | | |
622 |
623 | ```sql
624 | SELECT *
625 | FROM customers
626 | LIMIT 6, 3;
627 | ```
628 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
629 | |-------------|------------|-----------|--------|-------|----------|------------|
630 | | | | | | | | |
631 | | | | | | | | |
632 |
633 | `Exercise`
634 | - Get the top three loyal customers
635 |
636 | `Solution`
637 | ```sql
638 | SELECT *
639 | FROM customers
640 | ORDER BY points DESC
641 | LIMIT 3;
642 | ```
643 | | customer_id | first_name | last_name | points | state | phone_no | birth_date |
644 | |-------------|------------|-----------|--------|-------|----------|------------|
645 | | | | | | | | |
646 | | | | | | | | |
647 |
648 | ## 2. Retrieving Data From a Multiple Table
649 | - ### 2.1 INNER Joins
650 | - `In INNER JOIN keyword, INNER is optional` both `INNER JOIN` & `JOIN` are same
651 |
652 | ```sql
653 | SELECT *
654 | FROM orders
655 | INNER JOIN customers
656 | ON orders.customer_id = customers.customer_id;
657 | ```
658 | ```sql
659 | SELECT *
660 | FROM orders
661 | JOIN customers
662 | ON orders.customer_id = customers.customer_id;
663 | ```
664 | | order_id | customer_id | orderr_date | status | comments | customer_id | first_name | last_name | points | state | phone_no | birth_date |
665 | |----------|-------------|-------------|--------|----------|-------------|------------|-----------|--------|-------|----------|------------|
666 | | | | | | | | | | | | | |
667 | | | | | | | | | | | | | |
668 |
669 | ```sql
670 | SELECT order_id, first_name, last_name
671 | FROM orders
672 | JOIN customers
673 | ON orders.customer_id = customers.customer_id;
674 | ```
675 | | order_id | first_name | last_name |
676 | |----------|------------|-----------|
677 | | | | |
678 | | | | |
679 |
680 | ```sql
681 | SELECT order_id, customer_id, first_name, last_name
682 | FROM orders
683 | JOIN customers
684 | ON orders.customer_id = customers.customer_id;
685 | ```
686 | #### `Error ⬆` `because of customer_id`
687 |
688 | ```sql
689 | SELECT order_id, orders.customer_id, first_name, last_name
690 | FROM orders
691 | JOIN customers
692 | ON orders.customer_id = customers.customer_id;
693 | ```
694 | ```sql
695 | SELECT order_id, o.customer_id, first_name, last_name
696 | FROM orders o
697 | JOIN customers c
698 | ON o.customer_id = c.customer_id;
699 | ```
700 | | order_id | customer_id | first_name | last_name |
701 | |----------|-------------|------------|-----------|
702 | | | | | |
703 | | | | | |
704 |
705 | `Exercise`
706 | - JOIN the order_items table with products table
707 | - each order returns all product_id as well as its name follewed by quantity and unit price from order_items table
708 |
709 | `Solution`
710 | ```sql
711 | SELECT *
712 | FROM order_items oi
713 | JOIN products p
714 | ON oi.product_id = p.product_id;
715 | ```
716 | | order_id | product_id | quantity | unit_price | name | quantity_in_stock | unit_price |
717 | |----------|------------|----------|------------|------|-------------------|------------|
718 | | | | | | | | |
719 | | | | | | | | |
720 | ```sql
721 | SELECT order_id, oi.product_id, quantity, unit_price
722 | FROM order_items oi
723 | JOIN products p
724 | ON oi.product_id = p.product_id;
725 | ```
726 | - `both unit_price are different`
727 |
728 | | order_id | product_id | quantity | unit_price | unit_price |
729 | |----------|------------|----------|------------|------------|
730 | | | | | | |
731 | | | | | | |
732 | ```sql
733 | SELECT order_id, oi.product_id, quantity, oi.unit_price
734 | FROM order_items oi
735 | JOIN products p
736 | ON oi.product_id = p.product_id;
737 | ```
738 | | order_id | product_id | quantity | unit_price |
739 | |----------|------------|----------|------------|
740 | | | | | |
741 | | | | | |
742 |
743 | - ### 2.2 Joining Across Databases
744 | ```sql
745 | USE sql_store;
746 |
747 | SELECT *
748 | FROM order_items oi
749 | JOIN sql_inventory.products p
750 | ON oi.product_id = p.product_id;
751 | ```
752 | ```sql
753 | USE sql_inventory;
754 |
755 | SELECT *
756 | FROM sql_store.order_items oi
757 | JOIN products p
758 | ON oi.product_id = p.product_id;
759 | ```
760 | | order_id | product_id | quantity | unit_price | product_id | name | quantity_in_stock | unit_price |
761 | |----------|------------|----------|------------|------------|------|-------------------|------------|
762 | | | | | | | | | |
763 | | | | | | | | | |
764 |
765 | - ### 2.3 Self Joins
766 | ```sql
767 | USE sql_hr;
768 |
769 | SELECT *
770 | FROM employees e
771 | JOIN employees m
772 | ON e.reports_to = m.employee_id;
773 | ```
774 | | employee_id | first_name | last_name | job_title | salary | reports_to | office_id | employee_id | first_name | last_name | job_title | salary | reports_to | office_id |
775 | |-------------|------------|-----------|-----------|--------|------------|-----------|-------------|------------|-----------|-----------|--------|------------|-----------|
776 | | | | | | | | | | | | | | | |
777 | | | | | | | | | | | | | | | |
778 |
779 | ```sql
780 | USE sql_hr;
781 |
782 | SELECT
783 | e.employee_id,
784 | e.first_name,
785 | m.first_name
786 | FROM employees e
787 | JOIN employees m
788 | ON e.reports_to = m.employee_id;
789 | ```
790 | | employee_id | first_name | first_name |
791 | |-------------|------------|------------|
792 | | | | |
793 | | | | |
794 |
795 | ```sql
796 | USE sql_hr;
797 |
798 | SELECT
799 | e.employee_id,
800 | e.first_name,
801 | m.first_name AS manager
802 | FROM employees e
803 | JOIN employees m
804 | ON e.reports_to = m.employee_id;
805 | ```
806 | | employee_id | first_name | manager |
807 | |-------------|------------|---------|
808 | | | | |
809 | | | | |
810 |
811 | - ### 2.4 Joining Multiple Tables
812 | ```sql
813 | USE sql_store;
814 |
815 | SELECT *
816 | FROM orders o
817 | JOIN customers c
818 | ON o.customer_id = c.customer_id
819 | JOIN order_statuses os
820 | ON o.status = os.order_status_id;
821 | ```
822 | | order_id | customer_id | order_date | status | order_status_id | comments | customer_id | first_name | last_name | points | state | phone_no | birth_date |
823 | |----------|-------------|------------|--------|-----------------|----------|-------------|------------|-----------|--------|-------|----------|------------|
824 | | | | | | | | | | | | | | |
825 | | | | | | | | | | | | | | |
826 |
827 | ```sql
828 | USE sql_store;
829 |
830 | SELECT
831 | o.order_id,
832 | o.order_date,
833 | c.first_name,
834 | c.last_name,
835 | os.name AS status
836 | FROM orders o
837 | JOIN customers c
838 | ON o.customer_id = c.customer_id
839 | JOIN order_statuses os
840 | ON o.status = os.order_status_id;
841 | ```
842 | | order_id | order_date | first_name | last_name | status |
843 | |----------|------------|------------|-----------|--------|
844 | | | | | | |
845 | | | | | | |
846 |
847 | - ### 2.5 Compound Join Conditions
848 | ```sql
849 | SELECT *
850 | FROM order_items oi
851 | JOIN order_item_notes oin
852 | ON oi.order_id = oin.order_id
853 | AND oi.product_id = oin.product_id;
854 | ```
855 | | order_id | product_id | order_date | status | comments | product_id | first_name | last_name | points | state | phone_no | birth_date |
856 | |----------|------------|------------|--------|----------|------------|------------|-----------|--------|-------|----------|------------|
857 | | | | | | | | | | | | | |
858 | | | | | | | | | | | | | |
859 |
860 | - ### 2.6 Implicit Join Syntax
861 | - `Explicit Inner Join Syntax`
862 | ```sql
863 | SELECT *
864 | FROM orders o
865 | JOIN customers c
866 | ON o.customer_id = c.customer_id;
867 | ```
868 | - `Implicit Inner Join Syntax`
869 | ```sql
870 | SELECT *
871 | FROM orders o, customers c
872 | WHERE o.customer_id = c.customer_id;
873 | ```
874 | | order_id | customer_id | orderr_date | status | comments | customer_id | first_name | last_name | points | state | phone_no | birth_date |
875 | |----------|-------------|-------------|--------|----------|-------------|------------|-----------|--------|-------|----------|------------|
876 | | | | | | | | | | | | | |
877 | | | | | | | | | | | | | |
878 |
879 | - ### 2.7 OUTER Joins
880 | - `OUTER Joins are two types`
881 | - `LEFT OUTER JOIN`
882 | - `RIGHT OUTER JOIN`
883 | - `And here also OUTER keyword is optional` `so write syntax as`
884 | - `LEFT JOIN`
885 | - `RIGHT JOIN`
886 | ```sql
887 | SELECT *
888 | FROM orders o
889 | LEFT OUTER JOIN customers c
890 | ON o.customer_id = c.customer_id
891 | ORDER BY c.customer_id;
892 | ```
893 | ```sql
894 | SELECT *
895 | FROM orders o
896 | LEFT JOIN customers c
897 | ON o.customer_id = c.customer_id
898 | ORDER BY c.customer_id;
899 | ```
900 | | order_id | customer_id | orderr_date | status | comments | customer_id | first_name | last_name | points | state | phone_no | birth_date |
901 | |----------|-------------|-------------|--------|----------|-------------|------------|-----------|--------|-------|----------|------------|
902 | | | | | | | | | | | | | |
903 | | | | | | | | | | | | | |
904 |
905 | ```sql
906 | SELECT *
907 | FROM orders o
908 | RIGHT OUTER JOIN customers c
909 | ON o.customer_id = c.customer_id
910 | ORDER BY c.customer_id;
911 | ```
912 | ```sql
913 | SELECT *
914 | FROM orders o
915 | RIGHT JOIN customers c
916 | ON o.customer_id = c.customer_id
917 | ORDER BY c.customer_id;
918 | ```
919 | | order_id | customer_id | orderr_date | status | comments | customer_id | first_name | last_name | points | state | phone_no | birth_date |
920 | |----------|-------------|-------------|--------|----------|-------------|------------|-----------|--------|-------|----------|------------|
921 | | | | | | | | | | | | | |
922 | | | | | | | | | | | | | |
923 |
924 | ```sql
925 | SELECT
926 | o.order_id,
927 | c.customer_id,
928 | c.first_name
929 | FROM orders o
930 | LEFT JOIN customers c
931 | ON o.customer_id = c.customer_id
932 | ORDER BY c.customer_id;
933 | ```
934 | | order_id | customer_id | first_name |
935 | |----------|-------------|------------|
936 | | | | |
937 | | | | |
938 |
939 | ```sql
940 | SELECT
941 | o.order_id,
942 | c.customer_id,
943 | c.first_name
944 | FROM orders o
945 | RIGHT JOIN customers c
946 | ON o.customer_id = c.customer_id
947 | ORDER BY c.customer_id;
948 | ```
949 | | order_id | customer_id | first_name |
950 | |----------|-------------|------------|
951 | | | | |
952 | | | | |
953 |
954 | - ### 2.8 OUTER Join Between Multiple Tables
955 | ```sql
956 | SELECT
957 | o.order_id,
958 | c.customer_id,
959 | c.first_name
960 | FROM orders o
961 | LEFT JOIN customers c
962 | ON o.customer_id = c.customer_id
963 | JOIN shippers sh
964 | ON o.shipper_id = sh.shipper_id
965 | ORDER BY c.customer_id;
966 | ```
967 | | order_id | customer_id | first_name |
968 | |----------|-------------|------------|
969 | | | | |
970 | | | | |
971 |
972 | ```sql
973 | SELECT
974 | o.order_id,
975 | c.customer_id,
976 | c.first_name,
977 | sh.name AS shipper
978 | FROM orders o
979 | LEFT JOIN customers c
980 | ON o.customer_id = c.customer_id
981 | LEFT JOIN shippers sh
982 | ON o.shipper_id = sh.shipper_id
983 | ORDER BY c.customer_id;
984 | ```
985 | | order_id | customer_id | first_name | shipper |
986 | |----------|-------------|------------|---------|
987 | | | | | |
988 | | | | | |
989 |
990 | - ### 2.9 Self Outer Joins
991 | ```sql
992 | USE sql_hr;
993 |
994 | SELECT
995 | e.employee_id,
996 | e.first_name,
997 | m.first_name AS manager
998 | FROM employees e
999 | LEFT JOIN employees m
1000 | ON e.reports_to = m.employee_id;
1001 | ```
1002 | | employee_id | first_name | manager |
1003 | |-------------|------------|---------|
1004 | | | | |
1005 | | | | |
1006 |
1007 | - ### 2.10 The USING Clause
1008 | - `use USING keyword if same column name in both tables`
1009 | ```sql
1010 | SELECT
1011 | o.order_id,
1012 | c.first_name
1013 | FROM orders o
1014 | JOIN customers c
1015 | ON o.customer_id = c.customer_id;
1016 | ```
1017 | ```sql
1018 | SELECT
1019 | o.order_id,
1020 | c.first_name
1021 | FROM orders o
1022 | JOIN customers c
1023 | USING (customer_id);
1024 | ```
1025 | | order_id | first_name |
1026 | |----------|------------|
1027 | | | |
1028 | | | |
1029 |
1030 | ```sql
1031 | SELECT *
1032 | FROM order_items oi
1033 | JOIN order_item_notes oin
1034 | ON oi.order_id = oin.order_id
1035 | AND oi.product_id = oin.product_id;
1036 | ```
1037 | ```sql
1038 | SELECT *
1039 | FROM order_items oi
1040 | JOIN order_item_notes oin
1041 | USING (order_id, product_id);
1042 | ```
1043 | | order_id | product_id | order_date | status | comments | product_id | first_name | last_name | points | state | phone_no | birth_date |
1044 | |----------|------------|------------|--------|----------|------------|------------|-----------|--------|-------|----------|------------|
1045 | | | | | | | | | | | | | |
1046 | | | | | | | | | | | | | |
1047 |
1048 | - ### 2.11 NATURAL Joins
1049 | ```sql
1050 | SELECT
1051 | o.order_id,
1052 | c.customer_id,
1053 | c.first_name
1054 | FROM orders o
1055 | NATURAL JOIN customers c;
1056 | ```
1057 | | order_id | customer_id | first_name |
1058 | |----------|-------------|------------|
1059 | | | | |
1060 | | | | |
1061 |
1062 | - ### 2.12 CROSS Joins
1063 | - `Explicit Inner Join Syntax`
1064 | ```sql
1065 | SELECT
1066 | c.first_name AS customer,
1067 | p.name AS product
1068 | FROM customers c
1069 | CROSS JOIN product p
1070 | ORDER BY c.first_name;
1071 | ```
1072 | - `Implicit Inner Join Syntax`
1073 | ```sql
1074 | SELECT
1075 | c.first_name AS customer,
1076 | p.name AS product
1077 | FROM customers c, product p
1078 | ORDER BY c.first_name;
1079 | ```
1080 | | customer | product |
1081 | |----------|---------|
1082 | | | |
1083 | | | |
1084 |
1085 | - ### 2.13 Unions
1086 | ```sql
1087 | SELECT
1088 | customer_id,
1089 | first_name,
1090 | points,
1091 | 'Bronze' AS type
1092 | FROM customers
1093 | WHERE points < 2000;
1094 |
1095 | UNION
1096 |
1097 | SELECT
1098 | customer_id,
1099 | first_name,
1100 | points,
1101 | 'Silver' AS type
1102 | FROM customers
1103 | WHERE points BETWEEN 2000 AND 3000;
1104 |
1105 | UNION
1106 |
1107 | SELECT
1108 | customer_id,
1109 | first_name,
1110 | points,
1111 | 'Gold' AS type
1112 | FROM customers
1113 | WHERE points > 3000
1114 |
1115 | ORDER BY first_name;
1116 | ```
1117 | | customer_id | first_name | points | type |
1118 | |-------------|------------|--------|------|
1119 | | | | | |
1120 | | | | | |
1121 |
1122 | ## 3. Inserting, Updating, and Deleting Data
1123 |
1124 |
--------------------------------------------------------------------------------
/comments.sql:
--------------------------------------------------------------------------------
1 |
2 |
3 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
4 | SET AUTOCOMMIT = 0;
5 | START TRANSACTION;
6 | SET time_zone = "+00:00";
7 |
8 |
9 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
10 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
11 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
12 | /*!40101 SET NAMES utf8mb4 */;
13 |
14 |
15 | -- --------------------------------------------------------
16 |
17 | --
18 | -- Table structure for table `comments`
19 | --
20 |
21 | CREATE TABLE `comments` (
22 | `ID` int(11) NOT NULL,
23 | `comment_author` varchar(256) NOT NULL,
24 | `comment_author_email` varchar(256) NOT NULL,
25 | `comment_content` longtext NOT NULL
26 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
27 |
28 | --
29 | -- Dumping data for table `comments`
30 | --
31 |
32 | INSERT INTO `comments` (`ID`, `comment_author`, `comment_author_email`, `comment_content`) VALUES
33 | (1, 'jessica', 'jessica@gmail.com', 'Great post! '),
34 | (2, 'mike', 'mike@gmail.com', 'Love it! Write more like this. '),
35 | (3, 'jamie', 'jamie@gmail.com', 'I disagree! '),
36 | (4, 'caleb', 'caleb@gmail.com', 'First');
37 |
38 | --
39 | -- Indexes for dumped tables
40 | --
41 |
42 | --
43 | -- Indexes for table `comments`
44 | --
45 | ALTER TABLE `comments`
46 | ADD PRIMARY KEY (`ID`);
47 |
48 | --
49 | -- AUTO_INCREMENT for dumped tables
50 | --
51 |
52 | --
53 | -- AUTO_INCREMENT for table `comments`
54 | --
55 | ALTER TABLE `comments`
56 | MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
57 | COMMIT;
58 |
59 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
60 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
61 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
62 |
--------------------------------------------------------------------------------
/databases.sql:
--------------------------------------------------------------------------------
1 | DROP DATABASE IF EXISTS `sql_invoicing`;
2 | CREATE DATABASE `sql_invoicing`;
3 | USE `sql_invoicing`;
4 |
5 | SET NAMES utf8 ;
6 | SET character_set_client = utf8mb4 ;
7 |
8 | CREATE TABLE `payment_methods` (
9 | `payment_method_id` tinyint(4) NOT NULL AUTO_INCREMENT,
10 | `name` varchar(50) NOT NULL,
11 | PRIMARY KEY (`payment_method_id`)
12 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
13 | INSERT INTO `payment_methods` VALUES (1,'Credit Card');
14 | INSERT INTO `payment_methods` VALUES (2,'Cash');
15 | INSERT INTO `payment_methods` VALUES (3,'PayPal');
16 | INSERT INTO `payment_methods` VALUES (4,'Wire Transfer');
17 |
18 | CREATE TABLE `clients` (
19 | `client_id` int(11) NOT NULL,
20 | `name` varchar(50) NOT NULL,
21 | `address` varchar(50) NOT NULL,
22 | `city` varchar(50) NOT NULL,
23 | `state` char(2) NOT NULL,
24 | `phone` varchar(50) DEFAULT NULL,
25 | PRIMARY KEY (`client_id`)
26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
27 | INSERT INTO `clients` VALUES (1,'Vinte','3 Nevada Parkway','Syracuse','NY','315-252-7305');
28 | INSERT INTO `clients` VALUES (2,'Myworks','34267 Glendale Parkway','Huntington','WV','304-659-1170');
29 | INSERT INTO `clients` VALUES (3,'Yadel','096 Pawling Parkway','San Francisco','CA','415-144-6037');
30 | INSERT INTO `clients` VALUES (4,'Kwideo','81674 Westerfield Circle','Waco','TX','254-750-0784');
31 | INSERT INTO `clients` VALUES (5,'Topiclounge','0863 Farmco Road','Portland','OR','971-888-9129');
32 |
33 | CREATE TABLE `invoices` (
34 | `invoice_id` int(11) NOT NULL,
35 | `number` varchar(50) NOT NULL,
36 | `client_id` int(11) NOT NULL,
37 | `invoice_total` decimal(9,2) NOT NULL,
38 | `payment_total` decimal(9,2) NOT NULL DEFAULT '0.00',
39 | `invoice_date` date NOT NULL,
40 | `due_date` date NOT NULL,
41 | `payment_date` date DEFAULT NULL,
42 | PRIMARY KEY (`invoice_id`),
43 | KEY `FK_client_id` (`client_id`),
44 | CONSTRAINT `FK_client_id` FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON DELETE RESTRICT ON UPDATE CASCADE
45 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
46 | INSERT INTO `invoices` VALUES (1,'91-953-3396',2,101.79,0.00,'2019-03-09','2019-03-29',NULL);
47 | INSERT INTO `invoices` VALUES (2,'03-898-6735',5,175.32,8.18,'2019-06-11','2019-07-01','2019-02-12');
48 | INSERT INTO `invoices` VALUES (3,'20-228-0335',5,147.99,0.00,'2019-07-31','2019-08-20',NULL);
49 | INSERT INTO `invoices` VALUES (4,'56-934-0748',3,152.21,0.00,'2019-03-08','2019-03-28',NULL);
50 | INSERT INTO `invoices` VALUES (5,'87-052-3121',5,169.36,0.00,'2019-07-18','2019-08-07',NULL);
51 | INSERT INTO `invoices` VALUES (6,'75-587-6626',1,157.78,74.55,'2019-01-29','2019-02-18','2019-01-03');
52 | INSERT INTO `invoices` VALUES (7,'68-093-9863',3,133.87,0.00,'2019-09-04','2019-09-24',NULL);
53 | INSERT INTO `invoices` VALUES (8,'78-145-1093',1,189.12,0.00,'2019-05-20','2019-06-09',NULL);
54 | INSERT INTO `invoices` VALUES (9,'77-593-0081',5,172.17,0.00,'2019-07-09','2019-07-29',NULL);
55 | INSERT INTO `invoices` VALUES (10,'48-266-1517',1,159.50,0.00,'2019-06-30','2019-07-20',NULL);
56 | INSERT INTO `invoices` VALUES (11,'20-848-0181',3,126.15,0.03,'2019-01-07','2019-01-27','2019-01-11');
57 | INSERT INTO `invoices` VALUES (13,'41-666-1035',5,135.01,87.44,'2019-06-25','2019-07-15','2019-01-26');
58 | INSERT INTO `invoices` VALUES (15,'55-105-9605',3,167.29,80.31,'2019-11-25','2019-12-15','2019-01-15');
59 | INSERT INTO `invoices` VALUES (16,'10-451-8824',1,162.02,0.00,'2019-03-30','2019-04-19',NULL);
60 | INSERT INTO `invoices` VALUES (17,'33-615-4694',3,126.38,68.10,'2019-07-30','2019-08-19','2019-01-15');
61 | INSERT INTO `invoices` VALUES (18,'52-269-9803',5,180.17,42.77,'2019-05-23','2019-06-12','2019-01-08');
62 | INSERT INTO `invoices` VALUES (19,'83-559-4105',1,134.47,0.00,'2019-11-23','2019-12-13',NULL);
63 |
64 | CREATE TABLE `payments` (
65 | `payment_id` int(11) NOT NULL AUTO_INCREMENT,
66 | `client_id` int(11) NOT NULL,
67 | `invoice_id` int(11) NOT NULL,
68 | `date` date NOT NULL,
69 | `amount` decimal(9,2) NOT NULL,
70 | `payment_method` tinyint(4) NOT NULL,
71 | PRIMARY KEY (`payment_id`),
72 | KEY `fk_client_id_idx` (`client_id`),
73 | KEY `fk_invoice_id_idx` (`invoice_id`),
74 | KEY `fk_payment_payment_method_idx` (`payment_method`),
75 | CONSTRAINT `fk_payment_client` FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE CASCADE,
76 | CONSTRAINT `fk_payment_invoice` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`invoice_id`) ON UPDATE CASCADE,
77 | CONSTRAINT `fk_payment_payment_method` FOREIGN KEY (`payment_method`) REFERENCES `payment_methods` (`payment_method_id`)
78 | ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
79 | INSERT INTO `payments` VALUES (1,5,2,'2019-02-12',8.18,1);
80 | INSERT INTO `payments` VALUES (2,1,6,'2019-01-03',74.55,1);
81 | INSERT INTO `payments` VALUES (3,3,11,'2019-01-11',0.03,1);
82 | INSERT INTO `payments` VALUES (4,5,13,'2019-01-26',87.44,1);
83 | INSERT INTO `payments` VALUES (5,3,15,'2019-01-15',80.31,1);
84 | INSERT INTO `payments` VALUES (6,3,17,'2019-01-15',68.10,1);
85 | INSERT INTO `payments` VALUES (7,5,18,'2019-01-08',32.77,1);
86 | INSERT INTO `payments` VALUES (8,5,18,'2019-01-08',10.00,2);
87 |
88 |
89 | DROP DATABASE IF EXISTS `sql_store`;
90 | CREATE DATABASE `sql_store`;
91 | USE `sql_store`;
92 |
93 | CREATE TABLE `products` (
94 | `product_id` int(11) NOT NULL AUTO_INCREMENT,
95 | `name` varchar(50) NOT NULL,
96 | `quantity_in_stock` int(11) NOT NULL,
97 | `unit_price` decimal(4,2) NOT NULL,
98 | PRIMARY KEY (`product_id`)
99 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
100 | INSERT INTO `products` VALUES (1,'Foam Dinner Plate',70,1.21);
101 | INSERT INTO `products` VALUES (2,'Pork - Bacon,back Peameal',49,4.65);
102 | INSERT INTO `products` VALUES (3,'Lettuce - Romaine, Heart',38,3.35);
103 | INSERT INTO `products` VALUES (4,'Brocolinni - Gaylan, Chinese',90,4.53);
104 | INSERT INTO `products` VALUES (5,'Sauce - Ranch Dressing',94,1.63);
105 | INSERT INTO `products` VALUES (6,'Petit Baguette',14,2.39);
106 | INSERT INTO `products` VALUES (7,'Sweet Pea Sprouts',98,3.29);
107 | INSERT INTO `products` VALUES (8,'Island Oasis - Raspberry',26,0.74);
108 | INSERT INTO `products` VALUES (9,'Longan',67,2.26);
109 | INSERT INTO `products` VALUES (10,'Broom - Push',6,1.09);
110 |
111 |
112 | CREATE TABLE `shippers` (
113 | `shipper_id` smallint(6) NOT NULL AUTO_INCREMENT,
114 | `name` varchar(50) NOT NULL,
115 | PRIMARY KEY (`shipper_id`)
116 | ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
117 | INSERT INTO `shippers` VALUES (1,'Hettinger LLC');
118 | INSERT INTO `shippers` VALUES (2,'Schinner-Predovic');
119 | INSERT INTO `shippers` VALUES (3,'Satterfield LLC');
120 | INSERT INTO `shippers` VALUES (4,'Mraz, Renner and Nolan');
121 | INSERT INTO `shippers` VALUES (5,'Waters, Mayert and Prohaska');
122 |
123 |
124 | CREATE TABLE `customers` (
125 | `customer_id` int(11) NOT NULL AUTO_INCREMENT,
126 | `first_name` varchar(50) NOT NULL,
127 | `last_name` varchar(50) NOT NULL,
128 | `birth_date` date DEFAULT NULL,
129 | `phone` varchar(50) DEFAULT NULL,
130 | `address` varchar(50) NOT NULL,
131 | `city` varchar(50) NOT NULL,
132 | `state` char(2) NOT NULL,
133 | `points` int(11) NOT NULL DEFAULT '0',
134 | PRIMARY KEY (`customer_id`)
135 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
136 | INSERT INTO `customers` VALUES (1,'Babara','MacCaffrey','1986-03-28','781-932-9754','0 Sage Terrace','Waltham','MA',2273);
137 | INSERT INTO `customers` VALUES (2,'Ines','Brushfield','1986-04-13','804-427-9456','14187 Commercial Trail','Hampton','VA',947);
138 | INSERT INTO `customers` VALUES (3,'Freddi','Boagey','1985-02-07','719-724-7869','251 Springs Junction','Colorado Springs','CO',2967);
139 | INSERT INTO `customers` VALUES (4,'Ambur','Roseburgh','1974-04-14','407-231-8017','30 Arapahoe Terrace','Orlando','FL',457);
140 | INSERT INTO `customers` VALUES (5,'Clemmie','Betchley','1973-11-07',NULL,'5 Spohn Circle','Arlington','TX',3675);
141 | INSERT INTO `customers` VALUES (6,'Elka','Twiddell','1991-09-04','312-480-8498','7 Manley Drive','Chicago','IL',3073);
142 | INSERT INTO `customers` VALUES (7,'Ilene','Dowson','1964-08-30','615-641-4759','50 Lillian Crossing','Nashville','TN',1672);
143 | INSERT INTO `customers` VALUES (8,'Thacher','Naseby','1993-07-17','941-527-3977','538 Mosinee Center','Sarasota','FL',205);
144 | INSERT INTO `customers` VALUES (9,'Romola','Rumgay','1992-05-23','559-181-3744','3520 Ohio Trail','Visalia','CA',1486);
145 | INSERT INTO `customers` VALUES (10,'Levy','Mynett','1969-10-13','404-246-3370','68 Lawn Avenue','Atlanta','GA',796);
146 |
147 |
148 | CREATE TABLE `order_statuses` (
149 | `order_status_id` tinyint(4) NOT NULL,
150 | `name` varchar(50) NOT NULL,
151 | PRIMARY KEY (`order_status_id`)
152 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
153 | INSERT INTO `order_statuses` VALUES (1,'Processed');
154 | INSERT INTO `order_statuses` VALUES (2,'Shipped');
155 | INSERT INTO `order_statuses` VALUES (3,'Delivered');
156 |
157 |
158 | CREATE TABLE `orders` (
159 | `order_id` int(11) NOT NULL AUTO_INCREMENT,
160 | `customer_id` int(11) NOT NULL,
161 | `order_date` date NOT NULL,
162 | `status` tinyint(4) NOT NULL DEFAULT '1',
163 | `comments` varchar(2000) DEFAULT NULL,
164 | `shipped_date` date DEFAULT NULL,
165 | `shipper_id` smallint(6) DEFAULT NULL,
166 | PRIMARY KEY (`order_id`),
167 | KEY `fk_orders_customers_idx` (`customer_id`),
168 | KEY `fk_orders_shippers_idx` (`shipper_id`),
169 | KEY `fk_orders_order_statuses_idx` (`status`),
170 | CONSTRAINT `fk_orders_customers` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id`) ON UPDATE CASCADE,
171 | CONSTRAINT `fk_orders_order_statuses` FOREIGN KEY (`status`) REFERENCES `order_statuses` (`order_status_id`) ON UPDATE CASCADE,
172 | CONSTRAINT `fk_orders_shippers` FOREIGN KEY (`shipper_id`) REFERENCES `shippers` (`shipper_id`) ON UPDATE CASCADE
173 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
174 | INSERT INTO `orders` VALUES (1,6,'2019-01-30',1,NULL,NULL,NULL);
175 | INSERT INTO `orders` VALUES (2,7,'2018-08-02',2,NULL,'2018-08-03',4);
176 | INSERT INTO `orders` VALUES (3,8,'2017-12-01',1,NULL,NULL,NULL);
177 | INSERT INTO `orders` VALUES (4,2,'2017-01-22',1,NULL,NULL,NULL);
178 | INSERT INTO `orders` VALUES (5,5,'2017-08-25',2,'','2017-08-26',3);
179 | INSERT INTO `orders` VALUES (6,10,'2018-11-18',1,'Aliquam erat volutpat. In congue.',NULL,NULL);
180 | INSERT INTO `orders` VALUES (7,2,'2018-09-22',2,NULL,'2018-09-23',4);
181 | INSERT INTO `orders` VALUES (8,5,'2018-06-08',1,'Mauris enim leo, rhoncus sed, vestibulum sit amet, cursus id, turpis.',NULL,NULL);
182 | INSERT INTO `orders` VALUES (9,10,'2017-07-05',2,'Nulla mollis molestie lorem. Quisque ut erat.','2017-07-06',1);
183 | INSERT INTO `orders` VALUES (10,6,'2018-04-22',2,NULL,'2018-04-23',2);
184 |
185 |
186 | CREATE TABLE `order_items` (
187 | `order_id` int(11) NOT NULL AUTO_INCREMENT,
188 | `product_id` int(11) NOT NULL,
189 | `quantity` int(11) NOT NULL,
190 | `unit_price` decimal(4,2) NOT NULL,
191 | PRIMARY KEY (`order_id`,`product_id`),
192 | KEY `fk_order_items_products_idx` (`product_id`),
193 | CONSTRAINT `fk_order_items_orders` FOREIGN KEY (`order_id`) REFERENCES `orders` (`order_id`) ON UPDATE CASCADE,
194 | CONSTRAINT `fk_order_items_products` FOREIGN KEY (`product_id`) REFERENCES `products` (`product_id`) ON UPDATE CASCADE
195 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
196 | INSERT INTO `order_items` VALUES (1,4,4,3.74);
197 | INSERT INTO `order_items` VALUES (2,1,2,9.10);
198 | INSERT INTO `order_items` VALUES (2,4,4,1.66);
199 | INSERT INTO `order_items` VALUES (2,6,2,2.94);
200 | INSERT INTO `order_items` VALUES (3,3,10,9.12);
201 | INSERT INTO `order_items` VALUES (4,3,7,6.99);
202 | INSERT INTO `order_items` VALUES (4,10,7,6.40);
203 | INSERT INTO `order_items` VALUES (5,2,3,9.89);
204 | INSERT INTO `order_items` VALUES (6,1,4,8.65);
205 | INSERT INTO `order_items` VALUES (6,2,4,3.28);
206 | INSERT INTO `order_items` VALUES (6,3,4,7.46);
207 | INSERT INTO `order_items` VALUES (6,5,1,3.45);
208 | INSERT INTO `order_items` VALUES (7,3,7,9.17);
209 | INSERT INTO `order_items` VALUES (8,5,2,6.94);
210 | INSERT INTO `order_items` VALUES (8,8,2,8.59);
211 | INSERT INTO `order_items` VALUES (9,6,5,7.28);
212 | INSERT INTO `order_items` VALUES (10,1,10,6.01);
213 | INSERT INTO `order_items` VALUES (10,9,9,4.28);
214 |
215 | CREATE TABLE `sql_store`.`order_item_notes` (
216 | `note_id` INT NOT NULL,
217 | `order_Id` INT NOT NULL,
218 | `product_id` INT NOT NULL,
219 | `note` VARCHAR(255) NOT NULL,
220 | PRIMARY KEY (`note_id`));
221 |
222 | INSERT INTO `order_item_notes` (`note_id`, `order_Id`, `product_id`, `note`) VALUES ('1', '1', '2', 'first note');
223 | INSERT INTO `order_item_notes` (`note_id`, `order_Id`, `product_id`, `note`) VALUES ('2', '1', '2', 'second note');
224 |
225 |
226 | DROP DATABASE IF EXISTS `sql_hr`;
227 | CREATE DATABASE `sql_hr`;
228 | USE `sql_hr`;
229 |
230 |
231 | CREATE TABLE `offices` (
232 | `office_id` int(11) NOT NULL,
233 | `address` varchar(50) NOT NULL,
234 | `city` varchar(50) NOT NULL,
235 | `state` varchar(50) NOT NULL,
236 | PRIMARY KEY (`office_id`)
237 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
238 | INSERT INTO `offices` VALUES (1,'03 Reinke Trail','Cincinnati','OH');
239 | INSERT INTO `offices` VALUES (2,'5507 Becker Terrace','New York City','NY');
240 | INSERT INTO `offices` VALUES (3,'54 Northland Court','Richmond','VA');
241 | INSERT INTO `offices` VALUES (4,'08 South Crossing','Cincinnati','OH');
242 | INSERT INTO `offices` VALUES (5,'553 Maple Drive','Minneapolis','MN');
243 | INSERT INTO `offices` VALUES (6,'23 North Plaza','Aurora','CO');
244 | INSERT INTO `offices` VALUES (7,'9658 Wayridge Court','Boise','ID');
245 | INSERT INTO `offices` VALUES (8,'9 Grayhawk Trail','New York City','NY');
246 | INSERT INTO `offices` VALUES (9,'16862 Westend Hill','Knoxville','TN');
247 | INSERT INTO `offices` VALUES (10,'4 Bluestem Parkway','Savannah','GA');
248 |
249 |
250 |
251 | CREATE TABLE `employees` (
252 | `employee_id` int(11) NOT NULL,
253 | `first_name` varchar(50) NOT NULL,
254 | `last_name` varchar(50) NOT NULL,
255 | `job_title` varchar(50) NOT NULL,
256 | `salary` int(11) NOT NULL,
257 | `reports_to` int(11) DEFAULT NULL,
258 | `office_id` int(11) NOT NULL,
259 | PRIMARY KEY (`employee_id`),
260 | KEY `fk_employees_offices_idx` (`office_id`),
261 | KEY `fk_employees_employees_idx` (`reports_to`),
262 | CONSTRAINT `fk_employees_managers` FOREIGN KEY (`reports_to`) REFERENCES `employees` (`employee_id`),
263 | CONSTRAINT `fk_employees_offices` FOREIGN KEY (`office_id`) REFERENCES `offices` (`office_id`) ON UPDATE CASCADE
264 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
265 | INSERT INTO `employees` VALUES (37270,'Yovonnda','Magrannell','Executive Secretary',63996,NULL,10);
266 | INSERT INTO `employees` VALUES (33391,'D\'arcy','Nortunen','Account Executive',62871,37270,1);
267 | INSERT INTO `employees` VALUES (37851,'Sayer','Matterson','Statistician III',98926,37270,1);
268 | INSERT INTO `employees` VALUES (40448,'Mindy','Crissil','Staff Scientist',94860,37270,1);
269 | INSERT INTO `employees` VALUES (56274,'Keriann','Alloisi','VP Marketing',110150,37270,1);
270 | INSERT INTO `employees` VALUES (63196,'Alaster','Scutchin','Assistant Professor',32179,37270,2);
271 | INSERT INTO `employees` VALUES (67009,'North','de Clerc','VP Product Management',114257,37270,2);
272 | INSERT INTO `employees` VALUES (67370,'Elladine','Rising','Social Worker',96767,37270,2);
273 | INSERT INTO `employees` VALUES (68249,'Nisse','Voysey','Financial Advisor',52832,37270,2);
274 | INSERT INTO `employees` VALUES (72540,'Guthrey','Iacopetti','Office Assistant I',117690,37270,3);
275 | INSERT INTO `employees` VALUES (72913,'Kass','Hefferan','Computer Systems Analyst IV',96401,37270,3);
276 | INSERT INTO `employees` VALUES (75900,'Virge','Goodrum','Information Systems Manager',54578,37270,3);
277 | INSERT INTO `employees` VALUES (76196,'Mirilla','Janowski','Cost Accountant',119241,37270,3);
278 | INSERT INTO `employees` VALUES (80529,'Lynde','Aronson','Junior Executive',77182,37270,4);
279 | INSERT INTO `employees` VALUES (80679,'Mildrid','Sokale','Geologist II',67987,37270,4);
280 | INSERT INTO `employees` VALUES (84791,'Hazel','Tarbert','General Manager',93760,37270,4);
281 | INSERT INTO `employees` VALUES (95213,'Cole','Kesterton','Pharmacist',86119,37270,4);
282 | INSERT INTO `employees` VALUES (96513,'Theresa','Binney','Food Chemist',47354,37270,5);
283 | INSERT INTO `employees` VALUES (98374,'Estrellita','Daleman','Staff Accountant IV',70187,37270,5);
284 | INSERT INTO `employees` VALUES (115357,'Ivy','Fearey','Structural Engineer',92710,37270,5);
285 |
286 |
287 | DROP DATABASE IF EXISTS `sql_inventory`;
288 | CREATE DATABASE `sql_inventory`;
289 | USE `sql_inventory`;
290 |
291 |
292 | CREATE TABLE `products` (
293 | `product_id` int(11) NOT NULL AUTO_INCREMENT,
294 | `name` varchar(50) NOT NULL,
295 | `quantity_in_stock` int(11) NOT NULL,
296 | `unit_price` decimal(4,2) NOT NULL,
297 | PRIMARY KEY (`product_id`)
298 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
299 | INSERT INTO `products` VALUES (1,'Foam Dinner Plate',70,1.21);
300 | INSERT INTO `products` VALUES (2,'Pork - Bacon,back Peameal',49,4.65);
301 | INSERT INTO `products` VALUES (3,'Lettuce - Romaine, Heart',38,3.35);
302 | INSERT INTO `products` VALUES (4,'Brocolinni - Gaylan, Chinese',90,4.53);
303 | INSERT INTO `products` VALUES (5,'Sauce - Ranch Dressing',94,1.63);
304 | INSERT INTO `products` VALUES (6,'Petit Baguette',14,2.39);
305 | INSERT INTO `products` VALUES (7,'Sweet Pea Sprouts',98,3.29);
306 | INSERT INTO `products` VALUES (8,'Island Oasis - Raspberry',26,0.74);
307 | INSERT INTO `products` VALUES (9,'Longan',67,2.26);
308 | INSERT INTO `products` VALUES (10,'Broom - Push',6,1.09);
309 |
310 |
311 |
312 |
--------------------------------------------------------------------------------
/db-hr.sql:
--------------------------------------------------------------------------------
1 | DROP DATABASE IF EXISTS `sql_hr`;
2 | CREATE DATABASE `sql_hr`;
3 | USE `sql_hr`;
4 |
5 |
6 | CREATE TABLE `offices` (
7 | `office_id` int(11) NOT NULL,
8 | `address` varchar(50) NOT NULL,
9 | `city` varchar(50) NOT NULL,
10 | `state` varchar(50) NOT NULL,
11 | PRIMARY KEY (`office_id`)
12 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
13 | INSERT INTO `offices` VALUES (1,'03 Reinke Trail','Cincinnati','OH');
14 | INSERT INTO `offices` VALUES (2,'5507 Becker Terrace','New York City','NY');
15 | INSERT INTO `offices` VALUES (3,'54 Northland Court','Richmond','VA');
16 | INSERT INTO `offices` VALUES (4,'08 South Crossing','Cincinnati','OH');
17 | INSERT INTO `offices` VALUES (5,'553 Maple Drive','Minneapolis','MN');
18 | INSERT INTO `offices` VALUES (6,'23 North Plaza','Aurora','CO');
19 | INSERT INTO `offices` VALUES (7,'9658 Wayridge Court','Boise','ID');
20 | INSERT INTO `offices` VALUES (8,'9 Grayhawk Trail','New York City','NY');
21 | INSERT INTO `offices` VALUES (9,'16862 Westend Hill','Knoxville','TN');
22 | INSERT INTO `offices` VALUES (10,'4 Bluestem Parkway','Savannah','GA');
23 |
24 |
25 |
26 | CREATE TABLE `employees` (
27 | `employee_id` int(11) NOT NULL,
28 | `first_name` varchar(50) NOT NULL,
29 | `last_name` varchar(50) NOT NULL,
30 | `job_title` varchar(50) NOT NULL,
31 | `salary` int(11) NOT NULL,
32 | `reports_to` int(11) DEFAULT NULL,
33 | `office_id` int(11) NOT NULL,
34 | PRIMARY KEY (`employee_id`),
35 | KEY `fk_employees_offices_idx` (`office_id`),
36 | KEY `fk_employees_employees_idx` (`reports_to`),
37 | CONSTRAINT `fk_employees_managers` FOREIGN KEY (`reports_to`) REFERENCES `employees` (`employee_id`),
38 | CONSTRAINT `fk_employees_offices` FOREIGN KEY (`office_id`) REFERENCES `offices` (`office_id`) ON UPDATE CASCADE
39 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
40 | INSERT INTO `employees` VALUES (37270,'Yovonnda','Magrannell','Executive Secretary',63996,NULL,10);
41 | INSERT INTO `employees` VALUES (33391,'D\'arcy','Nortunen','Account Executive',62871,37270,1);
42 | INSERT INTO `employees` VALUES (37851,'Sayer','Matterson','Statistician III',98926,37270,1);
43 | INSERT INTO `employees` VALUES (40448,'Mindy','Crissil','Staff Scientist',94860,37270,1);
44 | INSERT INTO `employees` VALUES (56274,'Keriann','Alloisi','VP Marketing',110150,37270,1);
45 | INSERT INTO `employees` VALUES (63196,'Alaster','Scutchin','Assistant Professor',32179,37270,2);
46 | INSERT INTO `employees` VALUES (67009,'North','de Clerc','VP Product Management',114257,37270,2);
47 | INSERT INTO `employees` VALUES (67370,'Elladine','Rising','Social Worker',96767,37270,2);
48 | INSERT INTO `employees` VALUES (68249,'Nisse','Voysey','Financial Advisor',52832,37270,2);
49 | INSERT INTO `employees` VALUES (72540,'Guthrey','Iacopetti','Office Assistant I',117690,37270,3);
50 | INSERT INTO `employees` VALUES (72913,'Kass','Hefferan','Computer Systems Analyst IV',96401,37270,3);
51 | INSERT INTO `employees` VALUES (75900,'Virge','Goodrum','Information Systems Manager',54578,37270,3);
52 | INSERT INTO `employees` VALUES (76196,'Mirilla','Janowski','Cost Accountant',119241,37270,3);
53 | INSERT INTO `employees` VALUES (80529,'Lynde','Aronson','Junior Executive',77182,37270,4);
54 | INSERT INTO `employees` VALUES (80679,'Mildrid','Sokale','Geologist II',67987,37270,4);
55 | INSERT INTO `employees` VALUES (84791,'Hazel','Tarbert','General Manager',93760,37270,4);
56 | INSERT INTO `employees` VALUES (95213,'Cole','Kesterton','Pharmacist',86119,37270,4);
57 | INSERT INTO `employees` VALUES (96513,'Theresa','Binney','Food Chemist',47354,37270,5);
58 | INSERT INTO `employees` VALUES (98374,'Estrellita','Daleman','Staff Accountant IV',70187,37270,5);
59 | INSERT INTO `employees` VALUES (115357,'Ivy','Fearey','Structural Engineer',92710,37270,5);
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/db-inventory.sql:
--------------------------------------------------------------------------------
1 | DROP DATABASE IF EXISTS `sql_inventory`;
2 | CREATE DATABASE `sql_inventory`;
3 | USE `sql_inventory`;
4 |
5 |
6 | CREATE TABLE `products` (
7 | `product_id` int(11) NOT NULL AUTO_INCREMENT,
8 | `name` varchar(50) NOT NULL,
9 | `quantity_in_stock` int(11) NOT NULL,
10 | `unit_price` decimal(4,2) NOT NULL,
11 | PRIMARY KEY (`product_id`)
12 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
13 | INSERT INTO `products` VALUES (1,'Foam Dinner Plate',70,1.21);
14 | INSERT INTO `products` VALUES (2,'Pork - Bacon,back Peameal',49,4.65);
15 | INSERT INTO `products` VALUES (3,'Lettuce - Romaine, Heart',38,3.35);
16 | INSERT INTO `products` VALUES (4,'Brocolinni - Gaylan, Chinese',90,4.53);
17 | INSERT INTO `products` VALUES (5,'Sauce - Ranch Dressing',94,1.63);
18 | INSERT INTO `products` VALUES (6,'Petit Baguette',14,2.39);
19 | INSERT INTO `products` VALUES (7,'Sweet Pea Sprouts',98,3.29);
20 | INSERT INTO `products` VALUES (8,'Island Oasis - Raspberry',26,0.74);
21 | INSERT INTO `products` VALUES (9,'Longan',67,2.26);
22 | INSERT INTO `products` VALUES (10,'Broom - Push',6,1.09);
23 |
24 |
--------------------------------------------------------------------------------
/db-invoicing.sql:
--------------------------------------------------------------------------------
1 | DROP DATABASE IF EXISTS `invoicing`;
2 | CREATE DATABASE `invoicing`;
3 | USE `invoicing`;
4 |
5 | SET NAMES utf8 ;
6 | SET character_set_client = utf8mb4 ;
7 |
8 | CREATE TABLE `payment_methods` (
9 | `payment_method_id` tinyint(4) NOT NULL AUTO_INCREMENT,
10 | `name` varchar(50) NOT NULL,
11 | PRIMARY KEY (`payment_method_id`)
12 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
13 | INSERT INTO `payment_methods` VALUES (1,'Credit Card');
14 | INSERT INTO `payment_methods` VALUES (2,'Cash');
15 | INSERT INTO `payment_methods` VALUES (3,'PayPal');
16 | INSERT INTO `payment_methods` VALUES (4,'Wire Transfer');
17 |
18 | CREATE TABLE `clients` (
19 | `client_id` int(11) NOT NULL,
20 | `name` varchar(50) NOT NULL,
21 | `address` varchar(50) NOT NULL,
22 | `city` varchar(50) NOT NULL,
23 | `state` char(2) NOT NULL,
24 | `phone` varchar(50) DEFAULT NULL,
25 | PRIMARY KEY (`client_id`)
26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
27 | INSERT INTO `clients` VALUES (1,'Vinte','3 Nevada Parkway','Syracuse','NY','315-252-7305');
28 | INSERT INTO `clients` VALUES (2,'Myworks','34267 Glendale Parkway','Huntington','WV','304-659-1170');
29 | INSERT INTO `clients` VALUES (3,'Yadel','096 Pawling Parkway','San Francisco','CA','415-144-6037');
30 | INSERT INTO `clients` VALUES (4,'Kwideo','81674 Westerfield Circle','Waco','TX','254-750-0784');
31 | INSERT INTO `clients` VALUES (5,'Topiclounge','0863 Farmco Road','Portland','OR','971-888-9129');
32 |
33 | CREATE TABLE `invoices` (
34 | `invoice_id` int(11) NOT NULL,
35 | `number` varchar(50) NOT NULL,
36 | `client_id` int(11) NOT NULL,
37 | `invoice_total` decimal(9,2) NOT NULL,
38 | `payment_total` decimal(9,2) NOT NULL DEFAULT '0.00',
39 | `invoice_date` date NOT NULL,
40 | `due_date` date NOT NULL,
41 | `payment_date` date DEFAULT NULL,
42 | PRIMARY KEY (`invoice_id`),
43 | KEY `FK_client_id` (`client_id`),
44 | CONSTRAINT `FK_client_id` FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON DELETE RESTRICT ON UPDATE CASCADE
45 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
46 | INSERT INTO `invoices` VALUES (1,'91-953-3396',2,101.79,0.00,'2019-03-09','2019-03-29',NULL);
47 | INSERT INTO `invoices` VALUES (2,'03-898-6735',5,175.32,8.18,'2019-06-11','2019-07-01','2019-02-12');
48 | INSERT INTO `invoices` VALUES (3,'20-228-0335',5,147.99,0.00,'2019-07-31','2019-08-20',NULL);
49 | INSERT INTO `invoices` VALUES (4,'56-934-0748',3,152.21,0.00,'2019-03-08','2019-03-28',NULL);
50 | INSERT INTO `invoices` VALUES (5,'87-052-3121',5,169.36,0.00,'2019-07-18','2019-08-07',NULL);
51 | INSERT INTO `invoices` VALUES (6,'75-587-6626',1,157.78,74.55,'2019-01-29','2019-02-18','2019-01-03');
52 | INSERT INTO `invoices` VALUES (7,'68-093-9863',3,133.87,0.00,'2019-09-04','2019-09-24',NULL);
53 | INSERT INTO `invoices` VALUES (8,'78-145-1093',1,189.12,0.00,'2019-05-20','2019-06-09',NULL);
54 | INSERT INTO `invoices` VALUES (9,'77-593-0081',5,172.17,0.00,'2019-07-09','2019-07-29',NULL);
55 | INSERT INTO `invoices` VALUES (10,'48-266-1517',1,159.50,0.00,'2019-06-30','2019-07-20',NULL);
56 | INSERT INTO `invoices` VALUES (11,'20-848-0181',3,126.15,0.03,'2019-01-07','2019-01-27','2019-01-11');
57 | INSERT INTO `invoices` VALUES (13,'41-666-1035',5,135.01,87.44,'2019-06-25','2019-07-15','2019-01-26');
58 | INSERT INTO `invoices` VALUES (15,'55-105-9605',3,167.29,80.31,'2019-11-25','2019-12-15','2019-01-15');
59 | INSERT INTO `invoices` VALUES (16,'10-451-8824',1,162.02,0.00,'2019-03-30','2019-04-19',NULL);
60 | INSERT INTO `invoices` VALUES (17,'33-615-4694',3,126.38,68.10,'2019-07-30','2019-08-19','2019-01-15');
61 | INSERT INTO `invoices` VALUES (18,'52-269-9803',5,180.17,42.77,'2019-05-23','2019-06-12','2019-01-08');
62 | INSERT INTO `invoices` VALUES (19,'83-559-4105',1,134.47,0.00,'2019-11-23','2019-12-13',NULL);
63 |
64 | CREATE TABLE `payments` (
65 | `payment_id` int(11) NOT NULL AUTO_INCREMENT,
66 | `client_id` int(11) NOT NULL,
67 | `invoice_id` int(11) NOT NULL,
68 | `date` date NOT NULL,
69 | `amount` decimal(9,2) NOT NULL,
70 | `payment_method` tinyint(4) NOT NULL,
71 | PRIMARY KEY (`payment_id`),
72 | KEY `fk_client_id_idx` (`client_id`),
73 | KEY `fk_invoice_id_idx` (`invoice_id`),
74 | KEY `fk_payment_payment_method_idx` (`payment_method`),
75 | CONSTRAINT `fk_payment_client` FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE CASCADE,
76 | CONSTRAINT `fk_payment_invoice` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`invoice_id`) ON UPDATE CASCADE,
77 | CONSTRAINT `fk_payment_payment_method` FOREIGN KEY (`payment_method`) REFERENCES `payment_methods` (`payment_method_id`)
78 | ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
79 | INSERT INTO `payments` VALUES (1,5,2,'2019-02-12',8.18,1);
80 | INSERT INTO `payments` VALUES (2,1,6,'2019-01-03',74.55,1);
81 | INSERT INTO `payments` VALUES (3,3,11,'2019-01-11',0.03,1);
82 | INSERT INTO `payments` VALUES (4,5,13,'2019-01-26',87.44,1);
83 | INSERT INTO `payments` VALUES (5,3,15,'2019-01-15',80.31,1);
84 | INSERT INTO `payments` VALUES (6,3,17,'2019-01-15',68.10,1);
85 | INSERT INTO `payments` VALUES (7,5,18,'2019-01-08',32.77,1);
86 | INSERT INTO `payments` VALUES (8,5,18,'2019-01-08',10.00,2);
87 |
--------------------------------------------------------------------------------
/db-store.sql:
--------------------------------------------------------------------------------
1 |
2 | DROP DATABASE IF EXISTS `store`;
3 | CREATE DATABASE `store`;
4 | USE `store`;
5 |
6 | CREATE TABLE `products` (
7 | `product_id` int(11) NOT NULL AUTO_INCREMENT,
8 | `name` varchar(50) NOT NULL,
9 | `quantity_in_stock` int(11) NOT NULL,
10 | `unit_price` decimal(4,2) NOT NULL,
11 | PRIMARY KEY (`product_id`)
12 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
13 | INSERT INTO `products` VALUES (1,'Foam Dinner Plate',70,1.21);
14 | INSERT INTO `products` VALUES (2,'Pork - Bacon,back Peameal',49,4.65);
15 | INSERT INTO `products` VALUES (3,'Lettuce - Romaine, Heart',38,3.35);
16 | INSERT INTO `products` VALUES (4,'Brocolinni - Gaylan, Chinese',90,4.53);
17 | INSERT INTO `products` VALUES (5,'Sauce - Ranch Dressing',94,1.63);
18 | INSERT INTO `products` VALUES (6,'Petit Baguette',14,2.39);
19 | INSERT INTO `products` VALUES (7,'Sweet Pea Sprouts',98,3.29);
20 | INSERT INTO `products` VALUES (8,'Island Oasis - Raspberry',26,0.74);
21 | INSERT INTO `products` VALUES (9,'Longan',67,2.26);
22 | INSERT INTO `products` VALUES (10,'Broom - Push',6,1.09);
23 |
24 |
25 | CREATE TABLE `shippers` (
26 | `shipper_id` smallint(6) NOT NULL AUTO_INCREMENT,
27 | `name` varchar(50) NOT NULL,
28 | PRIMARY KEY (`shipper_id`)
29 | ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
30 | INSERT INTO `shippers` VALUES (1,'Hettinger LLC');
31 | INSERT INTO `shippers` VALUES (2,'Schinner-Predovic');
32 | INSERT INTO `shippers` VALUES (3,'Satterfield LLC');
33 | INSERT INTO `shippers` VALUES (4,'Mraz, Renner and Nolan');
34 | INSERT INTO `shippers` VALUES (5,'Waters, Mayert and Prohaska');
35 |
36 |
37 | CREATE TABLE `customers` (
38 | `customer_id` int(11) NOT NULL AUTO_INCREMENT,
39 | `first_name` varchar(50) NOT NULL,
40 | `last_name` varchar(50) NOT NULL,
41 | `birth_date` date DEFAULT NULL,
42 | `phone` varchar(50) DEFAULT NULL,
43 | `address` varchar(50) NOT NULL,
44 | `city` varchar(50) NOT NULL,
45 | `state` char(2) NOT NULL,
46 | `points` int(11) NOT NULL DEFAULT '0',
47 | PRIMARY KEY (`customer_id`)
48 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
49 | INSERT INTO `customers` VALUES (1,'Babara','MacCaffrey','1986-03-28','781-932-9754','0 Sage Terrace','Waltham','MA',2273);
50 | INSERT INTO `customers` VALUES (2,'Ines','Brushfield','1986-04-13','804-427-9456','14187 Commercial Trail','Hampton','VA',947);
51 | INSERT INTO `customers` VALUES (3,'Freddi','Boagey','1985-02-07','719-724-7869','251 Springs Junction','Colorado Springs','CO',2967);
52 | INSERT INTO `customers` VALUES (4,'Ambur','Roseburgh','1974-04-14','407-231-8017','30 Arapahoe Terrace','Orlando','FL',457);
53 | INSERT INTO `customers` VALUES (5,'Clemmie','Betchley','1973-11-07',NULL,'5 Spohn Circle','Arlington','TX',3675);
54 | INSERT INTO `customers` VALUES (6,'Elka','Twiddell','1991-09-04','312-480-8498','7 Manley Drive','Chicago','IL',3073);
55 | INSERT INTO `customers` VALUES (7,'Ilene','Dowson','1964-08-30','615-641-4759','50 Lillian Crossing','Nashville','TN',1672);
56 | INSERT INTO `customers` VALUES (8,'Thacher','Naseby','1993-07-17','941-527-3977','538 Mosinee Center','Sarasota','FL',205);
57 | INSERT INTO `customers` VALUES (9,'Romola','Rumgay','1992-05-23','559-181-3744','3520 Ohio Trail','Visalia','CA',1486);
58 | INSERT INTO `customers` VALUES (10,'Levy','Mynett','1969-10-13','404-246-3370','68 Lawn Avenue','Atlanta','GA',796);
59 |
60 |
61 | CREATE TABLE `order_statuses` (
62 | `order_status_id` tinyint(4) NOT NULL,
63 | `name` varchar(50) NOT NULL,
64 | PRIMARY KEY (`order_status_id`)
65 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
66 | INSERT INTO `order_statuses` VALUES (1,'Processed');
67 | INSERT INTO `order_statuses` VALUES (2,'Shipped');
68 | INSERT INTO `order_statuses` VALUES (3,'Delivered');
69 |
70 |
71 | CREATE TABLE `orders` (
72 | `order_id` int(11) NOT NULL AUTO_INCREMENT,
73 | `customer_id` int(11) NOT NULL,
74 | `order_date` date NOT NULL,
75 | `status` tinyint(4) NOT NULL DEFAULT '1',
76 | `comments` varchar(2000) DEFAULT NULL,
77 | `shipped_date` date DEFAULT NULL,
78 | `shipper_id` smallint(6) DEFAULT NULL,
79 | PRIMARY KEY (`order_id`),
80 | KEY `fk_orders_customers_idx` (`customer_id`),
81 | KEY `fk_orders_shippers_idx` (`shipper_id`),
82 | KEY `fk_orders_order_statuses_idx` (`status`),
83 | CONSTRAINT `fk_orders_customers` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id`) ON UPDATE CASCADE,
84 | CONSTRAINT `fk_orders_order_statuses` FOREIGN KEY (`status`) REFERENCES `order_statuses` (`order_status_id`) ON UPDATE CASCADE,
85 | CONSTRAINT `fk_orders_shippers` FOREIGN KEY (`shipper_id`) REFERENCES `shippers` (`shipper_id`) ON UPDATE CASCADE
86 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
87 | INSERT INTO `orders` VALUES (1,6,'2019-01-30',1,NULL,NULL,NULL);
88 | INSERT INTO `orders` VALUES (2,7,'2018-08-02',2,NULL,'2018-08-03',4);
89 | INSERT INTO `orders` VALUES (3,8,'2017-12-01',1,NULL,NULL,NULL);
90 | INSERT INTO `orders` VALUES (4,2,'2017-01-22',1,NULL,NULL,NULL);
91 | INSERT INTO `orders` VALUES (5,5,'2017-08-25',2,'','2017-08-26',3);
92 | INSERT INTO `orders` VALUES (6,10,'2018-11-18',1,'Aliquam erat volutpat. In congue.',NULL,NULL);
93 | INSERT INTO `orders` VALUES (7,2,'2018-09-22',2,NULL,'2018-09-23',4);
94 | INSERT INTO `orders` VALUES (8,5,'2018-06-08',1,'Mauris enim leo, rhoncus sed, vestibulum sit amet, cursus id, turpis.',NULL,NULL);
95 | INSERT INTO `orders` VALUES (9,10,'2017-07-05',2,'Nulla mollis molestie lorem. Quisque ut erat.','2017-07-06',1);
96 | INSERT INTO `orders` VALUES (10,6,'2018-04-22',2,NULL,'2018-04-23',2);
97 |
98 |
99 | CREATE TABLE `order_items` (
100 | `order_id` int(11) NOT NULL AUTO_INCREMENT,
101 | `product_id` int(11) NOT NULL,
102 | `quantity` int(11) NOT NULL,
103 | `unit_price` decimal(4,2) NOT NULL,
104 | PRIMARY KEY (`order_id`,`product_id`),
105 | KEY `fk_order_items_products_idx` (`product_id`),
106 | CONSTRAINT `fk_order_items_orders` FOREIGN KEY (`order_id`) REFERENCES `orders` (`order_id`) ON UPDATE CASCADE,
107 | CONSTRAINT `fk_order_items_products` FOREIGN KEY (`product_id`) REFERENCES `products` (`product_id`) ON UPDATE CASCADE
108 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
109 | INSERT INTO `order_items` VALUES (1,4,4,3.74);
110 | INSERT INTO `order_items` VALUES (2,1,2,9.10);
111 | INSERT INTO `order_items` VALUES (2,4,4,1.66);
112 | INSERT INTO `order_items` VALUES (2,6,2,2.94);
113 | INSERT INTO `order_items` VALUES (3,3,10,9.12);
114 | INSERT INTO `order_items` VALUES (4,3,7,6.99);
115 | INSERT INTO `order_items` VALUES (4,10,7,6.40);
116 | INSERT INTO `order_items` VALUES (5,2,3,9.89);
117 | INSERT INTO `order_items` VALUES (6,1,4,8.65);
118 | INSERT INTO `order_items` VALUES (6,2,4,3.28);
119 | INSERT INTO `order_items` VALUES (6,3,4,7.46);
120 | INSERT INTO `order_items` VALUES (6,5,1,3.45);
121 | INSERT INTO `order_items` VALUES (7,3,7,9.17);
122 | INSERT INTO `order_items` VALUES (8,5,2,6.94);
123 | INSERT INTO `order_items` VALUES (8,8,2,8.59);
124 | INSERT INTO `order_items` VALUES (9,6,5,7.28);
125 | INSERT INTO `order_items` VALUES (10,1,10,6.01);
126 | INSERT INTO `order_items` VALUES (10,9,9,4.28);
127 |
128 | CREATE TABLE `sql_store`.`order_item_notes` (
129 | `note_id` INT NOT NULL,
130 | `order_Id` INT NOT NULL,
131 | `product_id` INT NOT NULL,
132 | `note` VARCHAR(255) NOT NULL,
133 | PRIMARY KEY (`note_id`));
134 |
135 | INSERT INTO `order_item_notes` (`note_id`, `order_Id`, `product_id`, `note`) VALUES ('1', '1', '2', 'first note');
136 | INSERT INTO `order_item_notes` (`note_id`, `order_Id`, `product_id`, `note`) VALUES ('2', '1', '2', 'second note');
137 |
--------------------------------------------------------------------------------
/facebook_users.sql:
--------------------------------------------------------------------------------
1 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
2 | SET AUTOCOMMIT = 0;
3 | START TRANSACTION;
4 | SET time_zone = "+00:00";
5 |
6 |
7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10 | /*!40101 SET NAMES utf8mb4 */;
11 |
12 | --
13 | -- Database: `db168432_sql`
14 | --
15 |
16 | -- --------------------------------------------------------
17 |
18 | --
19 | -- Table structure for table `facebook_users`
20 | --
21 |
22 | CREATE TABLE `facebook_users` (
23 | `ID` int(11) NOT NULL,
24 | `name` varchar(256) CHARACTER SET utf8 NOT NULL,
25 | `email` varchar(256) CHARACTER SET utf8 NOT NULL,
26 | `password` varchar(256) CHARACTER SET utf8 NOT NULL
27 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
28 |
29 | --
30 | -- Dumping data for table `facebook_users`
31 | --
32 |
33 | INSERT INTO `facebook_users` (`ID`, `name`, `email`, `password`) VALUES
34 | (1, 'chris', 'chris@gmail.com', '1234'),
35 | (3, 'mattan', 'mattan@gmail.com', '1234e41234e41234e41234e41234e4');
36 |
37 | --
38 | -- Indexes for dumped tables
39 | --
40 |
41 | --
42 | -- Indexes for table `facebook_users`
43 | --
44 | ALTER TABLE `facebook_users`
45 | ADD PRIMARY KEY (`ID`);
46 |
47 | --
48 | -- AUTO_INCREMENT for dumped tables
49 | --
50 |
51 | --
52 | -- AUTO_INCREMENT for table `facebook_users`
53 | --
54 | ALTER TABLE `facebook_users`
55 | MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
56 | COMMIT;
57 |
58 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
59 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
60 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
61 |
--------------------------------------------------------------------------------
/full database.sql:
--------------------------------------------------------------------------------
1 | -- phpMyAdmin SQL Dump
2 | -- version 4.9.1
3 | -- https://www.phpmyadmin.net/
4 | --
5 | -- Host: internal-db.s168432.gridserver.com
6 | -- Generation Time: Apr 21, 2020 at 08:26 PM
7 | -- Server version: 5.6.34-79.1
8 | -- PHP Version: 7.3.11
9 |
10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11 | SET AUTOCOMMIT = 0;
12 | START TRANSACTION;
13 | SET time_zone = "+00:00";
14 |
15 |
16 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
17 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
18 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
19 | /*!40101 SET NAMES utf8mb4 */;
20 |
21 | --
22 | -- Database: `db168432_sql`
23 | --
24 |
25 | -- --------------------------------------------------------
26 |
27 | --
28 | -- Table structure for table `comments`
29 | --
30 |
31 | CREATE TABLE `comments` (
32 | `ID` int(11) NOT NULL,
33 | `post_id` int(11) DEFAULT NULL,
34 | `comment_author` varchar(256) NOT NULL,
35 | `comment_author_email` varchar(256) NOT NULL,
36 | `comment_content` longtext NOT NULL
37 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
38 |
39 | --
40 | -- Dumping data for table `comments`
41 | --
42 |
43 | INSERT INTO `comments` (`ID`, `post_id`, `comment_author`, `comment_author_email`, `comment_content`) VALUES
44 | (1, 6, 'jessica', 'jessica@gmail.com', 'Great post! '),
45 | (2, 2, 'mike', 'mike@gmail.com', 'Love it! Write more like this. '),
46 | (3, 2, 'jamie', 'jamie@gmail.com', 'I disagree! '),
47 | (4, 2, 'caleb', 'caleb@gmail.com', 'First');
48 |
49 | -- --------------------------------------------------------
50 |
51 | --
52 | -- Table structure for table `facebook_users`
53 | --
54 |
55 | CREATE TABLE `facebook_users` (
56 | `ID` int(11) NOT NULL,
57 | `name` varchar(256) CHARACTER SET utf8 NOT NULL,
58 | `email` varchar(256) CHARACTER SET utf8 NOT NULL,
59 | `password` varchar(256) CHARACTER SET utf8 NOT NULL
60 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
61 |
62 | --
63 | -- Dumping data for table `facebook_users`
64 | --
65 |
66 | INSERT INTO `facebook_users` (`ID`, `name`, `email`, `password`) VALUES
67 | (1, 'chris', 'chris@gmail.com', '1234'),
68 | (3, 'mattan', 'mattan@gmail.com', '1234e41234e41234e41234e41234e4');
69 |
70 | -- --------------------------------------------------------
71 |
72 | --
73 | -- Table structure for table `posts`
74 | --
75 |
76 | CREATE TABLE `posts` (
77 | `ID` int(11) NOT NULL,
78 | `post_author` varchar(255) NOT NULL,
79 | `post_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL,
80 | `post_title` varchar(255) NOT NULL,
81 | `post_status` varchar(255) NOT NULL
82 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
83 |
84 | --
85 | -- Dumping data for table `posts`
86 | --
87 |
88 | INSERT INTO `posts` (`ID`, `post_author`, `post_content`, `post_title`, `post_status`) VALUES
89 | (1, '2', 'What is the toughest part of learning to code?\r\n\r\nSTAYING MOTIVATED.\r\n\r\nBack in 2002, I was a music major with no desire to become a computer programmer. I quit three times. I was still totally determined to make a website for my band ', '6 Reasons Why You’ll Never Learn to Code', 'published'),
90 | (2, '2', 'Python is one of the best coding languages to learn to boost your career. Many of the biggest websites in the world use Python, and there are plenty of jobs you can get with Python skills. But what do you need to know BEFORE you start?\r\n\r\nWith over four years experience teaching Python, we here at One Month have noticed 6 things that all new Python students should know before getting started.', 'What You Need to Know Before You Learn Python', 'published'),
91 | (3, '5', '
On Monday 63 Columbia University MBAs used One Month to build a website in under one hour. Did you know you could build a website from scratch in just one hour?
\r\n\r\n\r\n[caption id=\"attachment_3031\" align=\"alignnone\" width=\"1002\"]On Monday 63 Columbia University MBAs used One Month to build a website in under one hour. Did you know you could build a website from scratch in just one hour?
\r\n\r\n\r\n[caption id=\"attachment_3031\" align=\"alignnone\" width=\"1002\"]