-
Notifications
You must be signed in to change notification settings - Fork 1
/
SQL.txt
10126 lines (9362 loc) · 472 KB
/
SQL.txt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
mysql> CREATE USER 'admin' IDENTIFIED BY 'password1234';
Query OK, 0 rows affected (0.02 sec)
//CHANGE PASSWORD
mysql> ALTER USER 'admin' IDENTIFIED BY 'php1234';
Query OK, 0 rows affected (0.01 sec)
//GRANT ALL PRIVELLEGES TO ALL DB (*) ALL TABLES (*) TO THE USER 'ADMIN' WITH USER CAN SET PRIVELLEGES AND NEW USER
mysql> GRANT ALL ON *.* TO 'admin' WITH GRANT OPTION;
Query OK, 0 rows affected (0.02 sec)
//PRIVILEGES TO TAKE PLACE
mysql> FLUSH PRIVILEGES;
//EXIT TO LOG IN TO ADMIN
Microsoft Windows [Version 10.0.18362.836]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\ASUS>cd C:\Program Files\MySQL\MySQL Server 8.0\bin
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u admin -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.20 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.08 sec)
mysql> CREATE DATABASE school;
Query OK, 1 row affected (0.01 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+--------------------+
5 rows in set (0.00 sec)
/// Clear the Screen
system cls;
//see the column
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use school;
Database changed
mysql> use sql;
ERROR 1049 (42000): Unknown database 'sql'
mysql> use mysql;
Database changed
mysql> select user from user;
+------------------+
| user |
+------------------+
| admin |
| mysql.infoschema |
| mysql.session |
| mysql.sys |
| root |
+------------------+
5 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use school;
Database changed
mysql> use sql;
ERROR 1049 (42000): Unknown database 'sql'
mysql> use mysql;
Database changed
mysql> select user from user;
+------------------+
| user |
+------------------+
| admin |
| mysql.infoschema |
| mysql.session |
| mysql.sys |
| root |
+------------------+
5 rows in set (0.00 sec)
mysql> use school
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table students (
-> id INT NOT NULL PRIMARY KEY,
-> firstname VARCHAR(40) NOT NULL,
-> lastname VARCHAR(40) NOT NULL,
-> class VARCHAR(40) NOT NULL,
-> age INT
-> );
Query OK, 0 rows affected (0.07 sec)
mysql> DESC STUDENTS;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| id | int | NO | PRI | NULL | |
| firstname | varchar(40) | NO | | NULL | |
| lastname | varchar(40) | NO | | NULL | |
| class | varchar(40) | NO | | NULL | |
| age | int | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.05 sec)
mysql> SHOW TABLES;
+------------------+
| Tables_in_school |
+------------------+
| students |
+------------------+
1 row in set (0.00 sec)
mysql> DROP TABLE students;
Query OK, 0 rows affected (0.04 sec)
mysql> SHOW TABLES;
Empty set (0.00 sec)
mysql> DESC STUDENTS;
ERROR 1146 (42S02): Table 'school.students' doesn't exist
mysql> CREATE DATABASE school;
ERROR 1007 (HY000): Can't create database 'school'; database exists
mysql> USE SCHOOL;
Database changed
mysql> SHOW TABLES;
Empty set (0.00 sec)
mysql> CREATE TABLE students (
-> id INT NOT NULL PRIMARY KEY,
-> firstname VARCHAR(40) NOT NULL,
-> lastname VARCHAR(40) NOT NULL,
-> class VARCHAR(40) NOT NULL,
-> age INT,
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 7
mysql> CREATE TABLE students (
-> id INT NOT NULL PRIMARY KEY,
-> firstname VARCHAR(40) NOT NULL,
-> lastname VARCHAR(40) NOT NULL,
-> class VARCHAR(40) NOT NULL,
-> age INT
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> SHOW TABLES;
+------------------+
| Tables_in_school |
+------------------+
| students |
+------------------+
1 row in set (0.00 sec)
mysql> DESC STUDENTS;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| id | int | NO | PRI | NULL | |
| firstname | varchar(40) | NO | | NULL | |
| lastname | varchar(40) | NO | | NULL | |
| class | varchar(40) | NO | | NULL | |
| age | int | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> INSERT INTO students VALUES (1,'JOHN','SMITH','FIRST',5);
Query OK, 1 row affected (0.02 sec)
mysql> SELECT * FROM STUDENTS;
+----+-----------+----------+-------+------+
| id | firstname | lastname | class | age |
+----+-----------+----------+-------+------+
| 1 | JOHN | SMITH | FIRST | 5 |
+----+-----------+----------+-------+------+
1 row in set (0.00 sec)
mysql> INSERT INTO students (id,firstname,lastname,class,age) VALUES (2,'MIKA','SMITH','FIRST',15);
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM STUDENTS;
+----+-----------+----------+-------+------+
| id | firstname | lastname | class | age |
+----+-----------+----------+-------+------+
| 1 | JOHN | SMITH | FIRST | 5 |
| 2 | MIKA | SMITH | FIRST | 15 |
+----+-----------+----------+-------+------+
2 rows in set (0.00 sec)
mysql> INSERT INTO students (id,firstname,lastname,class,age) VALUES (2,'MIKA','SMITH','FIRST',15);
ERROR 1062 (23000): Duplicate entry '2' for key 'students.PRIMARY'
mysql> INSERT INTO students (id,firstname,lastname,class,age) VALUES
-> (3,'FAISAL','SHAH','THIRD',34);
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM STUDENTS;
+----+-----------+----------+-------+------+
| id | firstname | lastname | class | age |
+----+-----------+----------+-------+------+
| 1 | JOHN | SMITH | FIRST | 5 |
| 2 | MIKA | SMITH | FIRST | 15 |
| 3 | FAISAL | SHAH | THIRD | 34 |
+----+-----------+----------+-------+------+
3 rows in set (0.00 sec)
TWO TYPES OF SQL STATEMENTS;
1.Data Definition Language;
2.Data Manipulation Language;
DDL and DML both are SQL statements;
DDL changes the database structure while DML changes only the data.
Data Definition Language;
Manage database objects like tables and columns;
Changes the database structure;
Tables and column are created modified or removed
CREATE,ALTER AND DROP
Data Mainpulation Language;
Manage the data that resides in our tables and columns;
Changes only the data;
Data inside a table is inserted updated or deleted
INSERT UPDATE AND DELETE
///DataBases : School | Company | OnlineShop
///Tables : School :? Students | teachers | subjects
///Tables : Company :? Employess | Clients | Projects
/// Tables : Onlineshop :? Items | Categories | Customers |Orders
mysql> CREATE DATABASE school;
ERROR 1007 (HY000): Can't create database 'school'; database exists
mysql> CREATE DATABASE company;
Query OK, 1 row affected (0.01 sec)
mysql> CREATE DATABASE onlineshop;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| company |
| information_schema |
| mysql |
| onlineshop |
| performance_schema |
| school |
| sys |
+--------------------+
7 rows in set (0.00 sec)
mysql> USE school;
Database changed
mysql> CREATE TABLE students (
-> studentid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> firstname VARCHAR(40) NOT NULL,
-> lastname VARCHAR(40) NOT NULL,
-> class VARCHAR(20),
-> age INT(3)
-> );
Query OK, 0 rows affected, 1 warning (0.06 sec)
mysql> CREATE TABLE teachers (
-> teacherid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> name VARCHAR(80) NOT NULL,
-> phone VARCHAR(10)
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> CREATE TABLE subjects (
-> subjectid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> title VARCHAR(50) NOT NULL
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| students |
| subjects |
| teachers |
+------------------+
3 rows in set (0.01 sec)
mysql> USE company;
Database changed
mysql> CREATE TABLE employees (
-> employeeid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> name VARCHAR(80) NOT NULL,
-> jobtitle VARCHAR(50) NOT NULL,
-> salary FLOAT
-> );
Query OK, 0 rows affected (0.05 sec)
mysql> CREATE TABLE clients (
-> clientid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> name VARCHAR(80) NOT NULL,
-> phone VARCHAR(15),
-> address VARCHAR(150)
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> CREATE TABLE projects (
-> projectid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> title VARCHAR(200) NOT NULL,
-> clientid INT,
-> employeeid INT,
-> startdate DATETIME,
-> enddate DATETIME
-> );
Query OK, 0 rows affected (0.05 sec)
mysql> show tables;
+-------------------+
| Tables_in_company |
+-------------------+
| clients |
| employees |
| projects |
+-------------------+
3 rows in set (0.01 sec)
mysql> use onlineshop;
Database changed
mysql> CREATE TABLE items (
-> itemid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> categoryid INT,
-> name VARCHAR(100) NOT NULL,
-> price FLOAT
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> CREATE TABLE categories (
-> categoryid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> title VARCHAR(50) NOT NULL,
-> status TINYINT(1) NOT NULL
-> );
Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql> CREATE TABLE customers (
-> userid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> name VARCHAR(80) NOT NULL,
-> phone VARCHAR(15),
-> address VARCHAR(150)
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> CREATE TABLE orders (
-> orderid INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> userid INT,
-> items TEXT,
-> total FLOAT,
-> orderdate DATETIME
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> show tables;
+----------------------+
| Tables_in_onlineshop |
+----------------------+
| categories |
| customers |
| items |
| orders |
+----------------------+
4 rows in set (0.00 sec)
mysql> use school;
Database changed
mysql> INSERT INTO students (firstname, lastname, class, age) VALUES
-> ('John', 'Doe', 'First', 5),
-> ('Mary', 'Smith', 'Third', 7),
-> ('James', 'Brown', 'First', 5),
-> ('Mike', 'Walker', 'Second', 6),
-> ('Linda', 'Jones', 'Third', 7),
-> ('John', 'Doe', 'Third', 7),
-> ('James', 'Smith', 'First', 6),
-> ('John', 'Brown', 'Second', 6),
-> ('Daniel', 'Jones', 'First', 7),
-> ('Paul', 'Anderson', 'Third', 5),
-> ('Mark', 'Davis', 'Second', 6),
-> ('Steven', 'Thomas', 'First', 7),
-> ('Brian', 'King', 'Second', 5),
-> ('Kevin', 'Hall', 'First', 6),
-> ('Jason', 'Lee', 'Third', 5),
-> ('Jose', 'Young', 'First', 6),
-> ('Frank', 'Smith', 'First', 7),
-> ('Eric', 'Jones', 'Second', 7),
-> ('Jerry', 'Martin', 'Third', 5),
-> ('Peter', 'King', 'First', 6),
-> ('Henry', 'Clark', 'Second', 7),
-> ('Carl', 'White', 'Second', 5),
-> ('Joe', 'Thomas', 'First', 7),
-> ('Jack', 'Smith', 'Third', 6),
-> ('Roy', 'King', 'Second', 5),
-> ('Adam', 'Hall', 'First', 6),
-> ('Bobby', 'White', 'Second', 7),
-> ('Johnny', 'Davis', 'First', 6),
-> ('Jimmy', 'Jones', 'Third', 5),
-> ('Emma', 'Walker', 'First', 5),
-> ('Sophia', 'Walker', 'Third', 6),
-> ('Ava', 'Jones', 'First', 7),
-> ('Mia', 'Smith', 'Second', 6),
-> ('Emily', 'Walker', 'Second', 5),
-> ('Grace', 'King', 'First', 5),
-> ('Lillian', 'Jones', 'Third', 7),
-> ('Lily', 'King', 'Third', 6),
-> ('Layla', 'Young', 'First', 5),
-> ('Zoe', 'Thomas', 'Second', 7),
-> ('Anna', 'Jones', 'Second', 5),
-> ('Leah', 'Brown', 'Third', 6),
-> ('Camila', 'Hall', 'First', 5),
-> ('Riley', 'Martin', 'Third', 6),
-> ('Nora', 'Smith', 'Second', 7),
-> ('Hailey', 'Clark', 'Second', 7),
-> ('Ellie', 'King', 'Third', 5),
-> ('Lucy', 'Jones', 'Third', 6),
-> ('Stella', 'White', 'First', 5),
-> ('Bella', 'White', 'Second', 7),
-> ('Mila', 'Smith', 'Third', 6),
-> ('Maya', 'Brown', 'First', 5),
-> ('Faith', 'Thomas', 'Third', 5),
-> ('Eva', 'Brown', 'Second', 7),
-> ('Julia', 'King', 'Third', 6),
-> ('Ashley', 'Davis', 'First', 5),
-> ('Ruby', 'Young', 'Third', 7),
-> ('Alice', 'Jones', 'Second', 6),
-> ('Jasmine', 'Hall', 'Third', 7);
Query OK, 58 rows affected (0.02 sec)
Records: 58 Duplicates: 0 Warnings: 0
mysql> select * from students;
+-----------+-----------+----------+--------+------+
| studentid | firstname | lastname | class | age |
+-----------+-----------+----------+--------+------+
| 1 | John | Doe | First | 5 |
| 2 | Mary | Smith | Third | 7 |
| 3 | James | Brown | First | 5 |
| 4 | Mike | Walker | Second | 6 |
| 5 | Linda | Jones | Third | 7 |
| 6 | John | Doe | Third | 7 |
| 7 | James | Smith | First | 6 |
| 8 | John | Brown | Second | 6 |
| 9 | Daniel | Jones | First | 7 |
| 10 | Paul | Anderson | Third | 5 |
| 11 | Mark | Davis | Second | 6 |
| 12 | Steven | Thomas | First | 7 |
| 13 | Brian | King | Second | 5 |
| 14 | Kevin | Hall | First | 6 |
| 15 | Jason | Lee | Third | 5 |
| 16 | Jose | Young | First | 6 |
| 17 | Frank | Smith | First | 7 |
| 18 | Eric | Jones | Second | 7 |
| 19 | Jerry | Martin | Third | 5 |
| 20 | Peter | King | First | 6 |
| 21 | Henry | Clark | Second | 7 |
| 22 | Carl | White | Second | 5 |
| 23 | Joe | Thomas | First | 7 |
| 24 | Jack | Smith | Third | 6 |
| 25 | Roy | King | Second | 5 |
| 26 | Adam | Hall | First | 6 |
| 27 | Bobby | White | Second | 7 |
| 28 | Johnny | Davis | First | 6 |
| 29 | Jimmy | Jones | Third | 5 |
| 30 | Emma | Walker | First | 5 |
| 31 | Sophia | Walker | Third | 6 |
| 32 | Ava | Jones | First | 7 |
| 33 | Mia | Smith | Second | 6 |
| 34 | Emily | Walker | Second | 5 |
| 35 | Grace | King | First | 5 |
| 36 | Lillian | Jones | Third | 7 |
| 37 | Lily | King | Third | 6 |
| 38 | Layla | Young | First | 5 |
| 39 | Zoe | Thomas | Second | 7 |
| 40 | Anna | Jones | Second | 5 |
| 41 | Leah | Brown | Third | 6 |
| 42 | Camila | Hall | First | 5 |
| 43 | Riley | Martin | Third | 6 |
| 44 | Nora | Smith | Second | 7 |
| 45 | Hailey | Clark | Second | 7 |
| 46 | Ellie | King | Third | 5 |
| 47 | Lucy | Jones | Third | 6 |
| 48 | Stella | White | First | 5 |
| 49 | Bella | White | Second | 7 |
| 50 | Mila | Smith | Third | 6 |
| 51 | Maya | Brown | First | 5 |
| 52 | Faith | Thomas | Third | 5 |
| 53 | Eva | Brown | Second | 7 |
| 54 | Julia | King | Third | 6 |
| 55 | Ashley | Davis | First | 5 |
| 56 | Ruby | Young | Third | 7 |
| 57 | Alice | Jones | Second | 6 |
| 58 | Jasmine | Hall | Third | 7 |
+-----------+-----------+----------+--------+------+
58 rows in set (0.00 sec)
mysql> INSERT INTO teachers (name, phone) VALUES
-> ('John Doe', '1234567890'),
-> ('Caroline Smith', '0987654321'),
-> ('Jason King', '1234512345'),
-> ('Stella Brown', '0987612345'),
-> ('Eric Hall', '0987609876');
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM teachers;
+-----------+----------------+------------+
| teacherid | name | phone |
+-----------+----------------+------------+
| 1 | John Doe | 1234567890 |
| 2 | Caroline Smith | 0987654321 |
| 3 | Jason King | 1234512345 |
| 4 | Stella Brown | 0987612345 |
| 5 | Eric Hall | 0987609876 |
+-----------+----------------+------------+
5 rows in set (0.00 sec)
mysql> INSERT INTO subjects (title) VALUES ('English'), ('Mathematics'), ('Science'), ('Computer'), ('History'), ('Geography');
Query OK, 6 rows affected (0.01 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> select * from subjects;
+-----------+-------------+
| subjectid | title |
+-----------+-------------+
| 1 | English |
| 2 | Mathematics |
| 3 | Science |
| 4 | Computer |
| 5 | History |
| 6 | Geography |
+-----------+-------------+
6 rows in set (0.00 sec)
mysql> use company;
Database changed
mysql> INSERT INTO employees (name, jobtitle, salary) VALUES
-> ('John Doe', 'Web Developer', 3500.00),
-> ('Mary Smith', 'Web Developer', 3500.00),
-> ('James Brown', 'Web Developer', 3500.00),
-> ('Mike Walker', 'Web Developer', 3500.00),
-> ('Linda Jones', 'Web Developer', 3500.00),
-> ('John Doe', 'Systems Administrator', 3400.00),
-> ('James Smith', 'Systems Administrator', 3400.00),
-> ('John Brown', 'Systems Administrator', 3400.00),
-> ('Daniel Jones', 'Systems Administrator', 3400.00),
-> ('Paul Anderson', 'Systems Administrator', 3400.00),
-> ('Mark Davis', 'IT Support Manager', 3200.00),
-> ('Steven Thomas', 'IT Support Manager', 3200.00),
-> ('Brian King', 'IT Support Manager', 3200.00),
-> ('Kevin Hall', 'IT Support Manager', 3200.00),
-> ('Jason Lee', 'IT Support Manager', 3200.00),
-> ('Jose Young', 'Database Administrator', 3700.00),
-> ('Frank Smith', 'Database Administrator', 3700.00),
-> ('Eric Jones', 'Database Administrator', 3700.00),
-> ('Jerry Martin', 'Database Administrator', 3700.00),
-> ('Peter King', 'Database Administrator', 3700.00),
-> ('Henry Clark', 'Application Developer', 3800.00),
-> ('Carl White', 'Application Developer', 3800.00),
-> ('Joe Thomas', 'Application Developer', 3800.00),
-> ('Jack Smith', 'Application Developer', 3800.00),
-> ('Roy King', 'Application Developer', 3800.00);
Query OK, 25 rows affected (0.01 sec)
Records: 25 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM employees;
+------------+---------------+------------------------+--------+
| employeeid | name | jobtitle | salary |
+------------+---------------+------------------------+--------+
| 1 | John Doe | Web Developer | 3500 |
| 2 | Mary Smith | Web Developer | 3500 |
| 3 | James Brown | Web Developer | 3500 |
| 4 | Mike Walker | Web Developer | 3500 |
| 5 | Linda Jones | Web Developer | 3500 |
| 6 | John Doe | Systems Administrator | 3400 |
| 7 | James Smith | Systems Administrator | 3400 |
| 8 | John Brown | Systems Administrator | 3400 |
| 9 | Daniel Jones | Systems Administrator | 3400 |
| 10 | Paul Anderson | Systems Administrator | 3400 |
| 11 | Mark Davis | IT Support Manager | 3200 |
| 12 | Steven Thomas | IT Support Manager | 3200 |
| 13 | Brian King | IT Support Manager | 3200 |
| 14 | Kevin Hall | IT Support Manager | 3200 |
| 15 | Jason Lee | IT Support Manager | 3200 |
| 16 | Jose Young | Database Administrator | 3700 |
| 17 | Frank Smith | Database Administrator | 3700 |
| 18 | Eric Jones | Database Administrator | 3700 |
| 19 | Jerry Martin | Database Administrator | 3700 |
| 20 | Peter King | Database Administrator | 3700 |
| 21 | Henry Clark | Application Developer | 3800 |
| 22 | Carl White | Application Developer | 3800 |
| 23 | Joe Thomas | Application Developer | 3800 |
| 24 | Jack Smith | Application Developer | 3800 |
| 25 | Roy King | Application Developer | 3800 |
+------------+---------------+------------------------+--------+
25 rows in set (0.00 sec)
mysql> INSERT INTO clients (name, phone, address) VALUES
-> ('Jimmy Jones', '1234567890', 'Victoria Pavilion, Las Vegas, NV'),
-> ('Henry Clark', '0987654321', '4125 Sydney Place, Miami, FL'),
-> ('Ruby Young', '1234512345', '6170 Peshwar Place, Washington, DC'),
-> ('Julia King', '0987612345', 'MountainView Hospital, Victoria, TX');
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql>
mysql> select * from clients;
+----------+-------------+------------+-------------------------------------+
| clientid | name | phone | address |
+----------+-------------+------------+-------------------------------------+
| 1 | Jimmy Jones | 1234567890 | Victoria Pavilion, Las Vegas, NV |
| 2 | Henry Clark | 0987654321 | 4125 Sydney Place, Miami, FL |
| 3 | Ruby Young | 1234512345 | 6170 Peshwar Place, Washington, DC |
| 4 | Julia King | 0987612345 | MountainView Hospital, Victoria, TX |
+----------+-------------+------------+-------------------------------------+
4 rows in set (0.00 sec)
mysql> INSERT INTO projects ( title, clientid, employeeid, startdate, enddate) VALUES
-> ('Develop ecommerse website from scratch', 1, 3, NOW(), DATE_ADD(NOW(), INTERVAL 30 DAY)),
-> ('WordPress website for our company', 1, 2, NOW(), DATE_ADD(NOW(), INTERVAL 45 DAY)),
-> ('Manage our company servers', 2, 7, NOW(), DATE_ADD(NOW(), INTERVAL 45 DAY)),
-> ('Hosting account is not working', 3, 9, NOW(), DATE_ADD(NOW(), INTERVAL 7 DAY)),
-> ('MySQL database from my desktop application', 4, 17, NOW(), DATE_ADD(NOW(), INTERVAL 15 DAY)),
-> ('Develop new WordPress plugin for my business website', 2, NULL, NOW(), DATE_ADD(NOW(), INTERVAL 10 DAY)),
-> ('Migrate web application and database to new server', 2, NULL, NOW(), DATE_ADD(NOW(), INTERVAL 5 DAY)),
-> ('Android Application development', 4, 23, NOW(), DATE_ADD(NOW(), INTERVAL 30 DAY));
Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> select * from projects;
+-----------+------------------------------------------------------+----------+------------+---------------------+---------------------+
| projectid | title | clientid | employeeid | startdate | enddate |
+-----------+------------------------------------------------------+----------+------------+---------------------+---------------------+
| 1 | Develop ecommerse website from scratch | 1 | 3 | 2020-05-20 11:33:43 | 2020-06-19 11:33:43 |
| 2 | WordPress website for our company | 1 | 2 | 2020-05-20 11:33:43 | 2020-07-04 11:33:43 |
| 3 | Manage our company servers | 2 | 7 | 2020-05-20 11:33:43 | 2020-07-04 11:33:43 |
| 4 | Hosting account is not working | 3 | 9 | 2020-05-20 11:33:43 | 2020-05-27 11:33:43 |
| 5 | MySQL database from my desktop application | 4 | 17 | 2020-05-20 11:33:43 | 2020-06-04 11:33:43 |
| 6 | Develop new WordPress plugin for my business website | 2 | NULL | 2020-05-20 11:33:43 | 2020-05-30 11:33:43 |
| 7 | Migrate web application and database to new server | 2 | NULL | 2020-05-20 11:33:43 | 2020-05-25 11:33:43 |
| 8 | Android Application development | 4 | 23 | 2020-05-20 11:33:43 | 2020-06-19 11:33:43 |
+-----------+------------------------------------------------------+----------+------------+---------------------+---------------------+
8 rows in set (0.00 sec)
mysql> USE onlineshop;
Database changed
mysql> INSERT INTO categories (title, status) VALUES ('Electronics', 1), ('Books', 1), ('Cloths', 1);
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from categories;
+------------+-------------+--------+
| categoryid | title | status |
+------------+-------------+--------+
| 1 | Electronics | 1 |
| 2 | Books | 1 |
| 3 | Cloths | 1 |
+------------+-------------+--------+
3 rows in set (0.00 sec)
mysql> INSERT INTO items (categoryid, name, price) VALUES
-> (1, 'Android Mobile Phone', 250.00),
-> (1, 'i7 processor, 8GB RAM Laptop', 1000.00),
-> (2, 'How to train your cat', 25.00),
-> (2, 'Healthy dog food recipes', 19.00),
-> (2, 'Learn how to meditate for mental health', 30.00),
-> (3, 'Beautiful Black T-Shirts', 99.00),
-> (3, 'Blue Colored Jeans', 150.00);
Query OK, 7 rows affected (0.01 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql> select * from items;
+--------+------------+-----------------------------------------+-------+
| itemid | categoryid | name | price |
+--------+------------+-----------------------------------------+-------+
| 1 | 1 | Android Mobile Phone | 250 |
| 2 | 1 | i7 processor, 8GB RAM Laptop | 1000 |
| 3 | 2 | How to train your cat | 25 |
| 4 | 2 | Healthy dog food recipes | 19 |
| 5 | 2 | Learn how to meditate for mental health | 30 |
| 6 | 3 | Beautiful Black T-Shirts | 99 |
| 7 | 3 | Blue Colored Jeans | 150 |
+--------+------------+-----------------------------------------+-------+
7 rows in set (0.00 sec)
mysql> INSERT INTO customers (name, phone, address) VALUES
-> ('Jimmy Jones', '1234567890', 'Victoria Pavilion, Las Vegas, NV'),
-> ('Henry Clark', '0987654321', '4125 Sydney Place, Miami, FL'),
-> ('Ruby Young', '1234512345', '6170 Peshwar Place, Washington, DC'),
-> ('Julia King', '0987612345', 'MountainView Hospital, Victoria, TX'),
-> ('Anna Jones', '0987609876', '1234 Obere Street, Miami, FL');
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM customers;
+--------+-------------+------------+-------------------------------------+
| userid | name | phone | address |
+--------+-------------+------------+-------------------------------------+
| 1 | Jimmy Jones | 1234567890 | Victoria Pavilion, Las Vegas, NV |
| 2 | Henry Clark | 0987654321 | 4125 Sydney Place, Miami, FL |
| 3 | Ruby Young | 1234512345 | 6170 Peshwar Place, Washington, DC |
| 4 | Julia King | 0987612345 | MountainView Hospital, Victoria, TX |
| 5 | Anna Jones | 0987609876 | 1234 Obere Street, Miami, FL |
+--------+-------------+------------+-------------------------------------+
5 rows in set (0.00 sec)
mysql> INSERT INTO orders (userid, items, total, orderdate) VALUES
-> (2, 'i7 processor, 8GB RAM Laptop', 1000.00, NOW()),
-> (1, 'Healthy dog food recipes', 19.00, NOW()),
-> (25, 'Healthy dog food recipes', 19.00, NOW()),
-> (1, 'How to train your cat', 25.00, NOW()),
-> (3, 'Blue Colored Jeans', 150.00, NOW()),
-> (15, 'Beautiful Black T-Shirts', 99.00, NOW()),
-> (4, 'Beautiful Black T-Shirts', 99.00, NOW());
Query OK, 7 rows affected (0.01 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM orders;
+---------+--------+------------------------------+-------+---------------------+
| orderid | userid | items | total | orderdate |
+---------+--------+------------------------------+-------+---------------------+
| 1 | 2 | i7 processor, 8GB RAM Laptop | 1000 | 2020-05-20 11:35:39 |
| 2 | 1 | Healthy dog food recipes | 19 | 2020-05-20 11:35:39 |
| 3 | 25 | Healthy dog food recipes | 19 | 2020-05-20 11:35:39 |
| 4 | 1 | How to train your cat | 25 | 2020-05-20 11:35:39 |
| 5 | 3 | Blue Colored Jeans | 150 | 2020-05-20 11:35:39 |
| 6 | 15 | Beautiful Black T-Shirts | 99 | 2020-05-20 11:35:39 |
| 7 | 4 | Beautiful Black T-Shirts | 99 | 2020-05-20 11:35:39 |
+---------+--------+------------------------------+-------+---------------------+
7 rows in set (0.00 sec)
//// where clause and from clause importance in school and company databases;
mysql> select * from students where studentid=6;
+-----------+-----------+----------+-------+------+
| studentid | firstname | lastname | class | age |
+-----------+-----------+----------+-------+------+
| 6 | John | Doe | Third | 7 |
+-----------+-----------+----------+-------+------+
1 row in set (0.00 sec)
mysql> select * from students where firstname='John';
+-----------+-----------+----------+--------+------+
| studentid | firstname | lastname | class | age |
+-----------+-----------+----------+--------+------+
| 1 | John | Doe | First | 5 |
| 6 | John | Doe | Third | 7 |
| 8 | John | Brown | Second | 6 |
+-----------+-----------+----------+--------+------+
3 rows in set (0.00 sec)
mysql> use company;
Database changed
mysql> select * from employees where jobtitle ='Application Developer';
+------------+-------------+-----------------------+--------+
| employeeid | name | jobtitle | salary |
+------------+-------------+-----------------------+--------+
| 21 | Henry Clark | Application Developer | 3800 |
| 22 | Carl White | Application Developer | 3800 |
| 23 | Joe Thomas | Application Developer | 3800 |
| 24 | Jack Smith | Application Developer | 3800 |
| 25 | Roy King | Application Developer | 3800 |
+------------+-------------+-----------------------+--------+
5 rows in set (0.00 sec)
/// where clause depends up on a condition which evaluates as either be true,false or unknown;
mysql> use school;
Database changed
mysql> select * from students;
+-----------+-----------+----------+--------+------+
| studentid | firstname | lastname | class | age |
+-----------+-----------+----------+--------+------+
| 1 | John | Doe | First | 5 |
| 2 | Mary | Smith | Third | 7 |
| 3 | James | Brown | First | 5 |
| 4 | Mike | Walker | Second | 6 |
| 5 | Linda | Jones | Third | 7 |
| 6 | John | Doe | Third | 7 |
| 7 | James | Smith | First | 6 |
| 8 | John | Brown | Second | 6 |
| 9 | Daniel | Jones | First | 7 |
| 10 | Paul | Anderson | Third | 5 |
| 11 | Mark | Davis | Second | 6 |
| 12 | Steven | Thomas | First | 7 |
| 13 | Brian | King | Second | 5 |
| 14 | Kevin | Hall | First | 6 |
| 15 | Jason | Lee | Third | 5 |
| 16 | Jose | Young | First | 6 |
| 17 | Frank | Smith | First | 7 |
| 18 | Eric | Jones | Second | 7 |
| 19 | Jerry | Martin | Third | 5 |
| 20 | Peter | King | First | 6 |
| 21 | Henry | Clark | Second | 7 |
| 22 | Carl | White | Second | 5 |
| 23 | Joe | Thomas | First | 7 |
| 24 | Jack | Smith | Third | 6 |
| 25 | Roy | King | Second | 5 |
| 26 | Adam | Hall | First | 6 |
| 27 | Bobby | White | Second | 7 |
| 28 | Johnny | Davis | First | 6 |
| 29 | Jimmy | Jones | Third | 5 |
| 30 | Emma | Walker | First | 5 |
| 31 | Sophia | Walker | Third | 6 |
| 32 | Ava | Jones | First | 7 |
| 33 | Mia | Smith | Second | 6 |
| 34 | Emily | Walker | Second | 5 |
| 35 | Grace | King | First | 5 |
| 36 | Lillian | Jones | Third | 7 |
| 37 | Lily | King | Third | 6 |
| 38 | Layla | Young | First | 5 |
| 39 | Zoe | Thomas | Second | 7 |
| 40 | Anna | Jones | Second | 5 |
| 41 | Leah | Brown | Third | 6 |
| 42 | Camila | Hall | First | 5 |
| 43 | Riley | Martin | Third | 6 |
| 44 | Nora | Smith | Second | 7 |
| 45 | Hailey | Clark | Second | 7 |
| 46 | Ellie | King | Third | 5 |
| 47 | Lucy | Jones | Third | 6 |
| 48 | Stella | White | First | 5 |
| 49 | Bella | White | Second | 7 |
| 50 | Mila | Smith | Third | 6 |
| 51 | Maya | Brown | First | 5 |
| 52 | Faith | Thomas | Third | 5 |
| 53 | Eva | Brown | Second | 7 |
| 54 | Julia | King | Third | 6 |
| 55 | Ashley | Davis | First | 5 |
| 56 | Ruby | Young | Third | 7 |
| 57 | Alice | Jones | Second | 6 |
| 58 | Jasmine | Hall | Third | 7 |
+-----------+-----------+----------+--------+------+
58 rows in set (0.00 sec)
mysql> select * from students where studentid=6;
+-----------+-----------+----------+-------+------+
| studentid | firstname | lastname | class | age |
+-----------+-----------+----------+-------+------+
| 6 | John | Doe | Third | 7 |
+-----------+-----------+----------+-------+------+
1 row in set (0.00 sec)
mysql> select * from students where class='First';
+-----------+-----------+----------+-------+------+
| studentid | firstname | lastname | class | age |
+-----------+-----------+----------+-------+------+
| 1 | John | Doe | First | 5 |
| 3 | James | Brown | First | 5 |
| 7 | James | Smith | First | 6 |
| 9 | Daniel | Jones | First | 7 |
| 12 | Steven | Thomas | First | 7 |
| 14 | Kevin | Hall | First | 6 |
| 16 | Jose | Young | First | 6 |
| 17 | Frank | Smith | First | 7 |
| 20 | Peter | King | First | 6 |
| 23 | Joe | Thomas | First | 7 |
| 26 | Adam | Hall | First | 6 |
| 28 | Johnny | Davis | First | 6 |
| 30 | Emma | Walker | First | 5 |
| 32 | Ava | Jones | First | 7 |
| 35 | Grace | King | First | 5 |
| 38 | Layla | Young | First | 5 |
| 42 | Camila | Hall | First | 5 |
| 48 | Stella | White | First | 5 |
| 51 | Maya | Brown | First | 5 |
| 55 | Ashley | Davis | First | 5 |
+-----------+-----------+----------+-------+------+
20 rows in set (0.00 sec)
mysql> use company ;
Database changed
mysql> select * from employees where salary =3700;
+------------+--------------+------------------------+--------+
| employeeid | name | jobtitle | salary |
+------------+--------------+------------------------+--------+
| 16 | Jose Young | Database Administrator | 3700 |
| 17 | Frank Smith | Database Administrator | 3700 |
| 18 | Eric Jones | Database Administrator | 3700 |
| 19 | Jerry Martin | Database Administrator | 3700 |
| 20 | Peter King | Database Administrator | 3700 |
+------------+--------------+------------------------+--------+
5 rows in set (0.00 sec)
/// where clause with false condition;
/// <> not equal to and less than or greater than;
mysql> select * from students where NOT studentid =6;
+-----------+-----------+----------+--------+------+
| studentid | firstname | lastname | class | age |
+-----------+-----------+----------+--------+------+
| 1 | John | Doe | First | 5 |
| 2 | Mary | Smith | Third | 7 |
| 3 | James | Brown | First | 5 |
| 4 | Mike | Walker | Second | 6 |
| 5 | Linda | Jones | Third | 7 |
| 7 | James | Smith | First | 6 |
| 8 | John | Brown | Second | 6 |
| 9 | Daniel | Jones | First | 7 |
| 10 | Paul | Anderson | Third | 5 |
| 11 | Mark | Davis | Second | 6 |
| 12 | Steven | Thomas | First | 7 |
| 13 | Brian | King | Second | 5 |
| 14 | Kevin | Hall | First | 6 |
| 15 | Jason | Lee | Third | 5 |
| 16 | Jose | Young | First | 6 |
| 17 | Frank | Smith | First | 7 |
| 18 | Eric | Jones | Second | 7 |
| 19 | Jerry | Martin | Third | 5 |
| 20 | Peter | King | First | 6 |
| 21 | Henry | Clark | Second | 7 |
| 22 | Carl | White | Second | 5 |
| 23 | Joe | Thomas | First | 7 |
| 24 | Jack | Smith | Third | 6 |
| 25 | Roy | King | Second | 5 |
| 26 | Adam | Hall | First | 6 |
| 27 | Bobby | White | Second | 7 |
| 28 | Johnny | Davis | First | 6 |
| 29 | Jimmy | Jones | Third | 5 |
| 30 | Emma | Walker | First | 5 |
| 31 | Sophia | Walker | Third | 6 |
| 32 | Ava | Jones | First | 7 |
| 33 | Mia | Smith | Second | 6 |
| 34 | Emily | Walker | Second | 5 |
| 35 | Grace | King | First | 5 |
| 36 | Lillian | Jones | Third | 7 |
| 37 | Lily | King | Third | 6 |
| 38 | Layla | Young | First | 5 |
| 39 | Zoe | Thomas | Second | 7 |
| 40 | Anna | Jones | Second | 5 |
| 41 | Leah | Brown | Third | 6 |
| 42 | Camila | Hall | First | 5 |
| 43 | Riley | Martin | Third | 6 |
| 44 | Nora | Smith | Second | 7 |
| 45 | Hailey | Clark | Second | 7 |
| 46 | Ellie | King | Third | 5 |
| 47 | Lucy | Jones | Third | 6 |
| 48 | Stella | White | First | 5 |
| 49 | Bella | White | Second | 7 |
| 50 | Mila | Smith | Third | 6 |
| 51 | Maya | Brown | First | 5 |
| 52 | Faith | Thomas | Third | 5 |
| 53 | Eva | Brown | Second | 7 |
| 54 | Julia | King | Third | 6 |
| 55 | Ashley | Davis | First | 5 |