MYSQL-SQL COMMANDS STARTING A NEW TOUR TO LEARN A BACK-END LANGUAGE STRUCTURED QUERY LANGUAGE
Server version: 8.0.31 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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 |
+--------------------+
| admin |
| count |
| departemp |
| diedb |
| emp |
| employee |
| information_schema |
| mysql |
| performance_schema |
| school |
| school1 |
| sys |
+--------------------+
12 rows in set (0.02 sec)
mysql> create database TEACHER;
Query OK, 1 row affected (0.02 sec)
mysql> USE TEACHER;
Database changed
mysql> SHOW TABLES;
Empty set (0.02 sec)
mysql> CREATE TABLE TEACHERS (ID INT PRIMARY KEY,NAME CHAR(40),DEBT CHAR(40),HIREDATE DATE,CATEGORY CHAR(20),GENDER CHAR(5),SALARY BIGINT);
Query OK, 0 rows affected (0.03 sec)
mysql> DESC TEACHERS;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| ID | int | NO | PRI | NULL | |
| NAME | char(40) | YES | | NULL | |
| DEBT | char(40) | YES | | NULL | |
| HIREDATE | date | YES | | NULL | |
| CATEGORY | char(20) | YES | | NULL | |
| GENDER | char(5) | YES | | NULL | |
| SALARY | bigint | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
7 rows in set (0.02 sec)
mysql> INSERT INTO TEACHERS VALUES(1,"TANYA","SST","1994-03-17","TGT","F",25000);
Query OK, 1 row affected (0.02 sec)
mysql> INSERT INTO TEACHERS VALUES(2,"SOURABH","ART","1990-02-12","PRT","M",20000),
-> INSERT INTO TEACHERS VALUES(3,"NANDITA","ENG","1980-05-16","PGT","F",30000);
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 'INSERT INTO TEACHERS VALUES(3,"NANDITA","ENG","1980-05-16","PGT","F",30000)' at line 2
mysql> INSERT INTO TEACHERS VALUES(2,"SOURABH","ART","1990-02-12","PRT","M",20000);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO TEACHERS VALUES(3,"NANDITA","ENG","1980-05-16","PGT","F",30000);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO TEACHERS VALUES(4,"JAMES","ENG","1989-10-16","PGT","M",25000);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO TEACHERS VALUES(5,"JASPREET","HINDI","1990-08-01","TGT","F",22000);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO TEACHERS VALUES(6,"DISHA","MATHS","1980-03-17","PRT","F",21000);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO TEACHERS VALUES(7,"SONALI","MATHS","1980-11-17","TGT","F",24500);
Query OK, 1 row affected (0.01 sec)
mysql> SELECT*FROM TEACHERS;
+----+----------+-------+------------+----------+--------+--------+
| ID | NAME | DEBT | HIREDATE | CATEGORY | GENDER | SALARY |
+----+----------+-------+------------+----------+--------+--------+
| 1 | TANYA | SST | 1994-03-17 | TGT | F | 25000 |
| 2 | SOURABH | ART | 1990-02-12 | PRT | M | 20000 |
| 3 | NANDITA | ENG | 1980-05-16 | PGT | F | 30000 |
| 4 | JAMES | ENG | 1989-10-16 | PGT | M | 25000 |
| 5 | JASPREET | HINDI | 1990-08-01 | TGT | F | 22000 |
| 6 | DISHA | MATHS | 1980-03-17 | PRT | F | 21000 |
| 7 | SONALI | MATHS | 1980-11-17 | TGT | F | 24500 |
+----+----------+-------+------------+----------+--------+--------+
7 rows in set (0.00 sec)
mysql> SELECT * FROM TEACHERS WHERE CATEGORY="PGT";
+----+---------+------+------------+----------+--------+--------+
| ID | NAME | DEBT | HIREDATE | CATEGORY | GENDER | SALARY |
+----+---------+------+------------+----------+--------+--------+
| 3 | NANDITA | ENG | 1980-05-16 | PGT | F | 30000 |
| 4 | JAMES | ENG | 1989-10-16 | PGT | M | 25000 |
+----+---------+------+------------+----------+--------+--------+
2 rows in set (0.01 sec)
mysql> SELECT NAME FROM TEACHERS WHERE (GENDER="F",DEBT="HINDI");
ERROR 1241 (21000): Operand should contain 1 column(s)
mysql> SELECT NAME FROM TEACHERS WHERE (GENDER="F" AND DEBT="HINDI");
+----------+
| NAME |
+----------+
| JASPREET |
+----------+
1 row in set (0.00 sec)
mysql> SELECT NAME,DEBT,HIREDATE FROM TEACHERS;
+----------+-------+------------+
| NAME | DEBT | HIREDATE |
+----------+-------+------------+
| TANYA | SST | 1994-03-17 |
| SOURABH | ART | 1990-02-12 |
| NANDITA | ENG | 1980-05-16 |
| JAMES | ENG | 1989-10-16 |
| JASPREET | HINDI | 1990-08-01 |
| DISHA | MATHS | 1980-03-17 |
| SONALI | MATHS | 1980-11-17 |
+----------+-------+------------+
7 rows in set (0.00 sec)
mysql> COUNT WHERE DEBT="ENG";
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 'COUNT WHERE DEBT="ENG"' at line 1
mysql> COUNT() WHERE DEBT="ENG";
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 'COUNT() WHERE DEBT="ENG"' at line 1
mysql> COUNT() DEBT="ENG";
+------+------------+
| DEBT | HIREDATE |
+------+------------+
| SST | 1994-03-17 |
| ENG | 1980-05-16 |
+------+------------+
2 rows in set (0.04 sec)
mysql> SELECT * FROM TEACHERS WHERE NAME LIKE("J%");
+----+----------+-------+------------+----------+--------+--------+
| ID | NAME | DEBT | HIREDATE | CATEGORY | GENDER | SALARY |
+----+----------+-------+------------+----------+--------+--------+
| 4 | JAMES | ENG | 1989-10-16 | PGT | M | 25000 |
| 5 | JASPREET | HINDI | 1990-08-01 | TGT | F | 22000 |
+----+----------+-------+------------+----------+--------+--------+
2 rows in set (0.01 sec)
mysql> SELECT MONTHNAME (HIREDATE) FROM TEACHERS WHERE CATEGORY="TGT";
+----------------------+
| MONTHNAME (HIREDATE) |
+----------------------+
| March |
| August |
| November |
+----------------------+
3 rows in set (0.01 sec)
mysql> SELECT*FROM TEACHERS;
+----+----------+-------+------------+----------+--------+--------+
| ID | NAME | DEBT | HIREDATE | CATEGORY | GENDER | SALARY |
+----+----------+-------+------------+----------+--------+--------+
| 1 | TANYA | SST | 1994-03-17 | TGT | F | 25000 |
| 2 | SOURABH | ART | 1990-02-12 | PRT | M | 20000 |
| 3 | NANDITA | ENG | 1980-05-16 | PGT | F | 30000 |
| 4 | JAMES | ENG | 1989-10-16 | PGT | M | 25000 |
| 5 | JASPREET | HINDI | 1990-08-01 | TGT | F | 22000 |
| 6 | DISHA | MATHS | 1980-03-17 | PRT | F | 21000 |
| 7 | SONALI | MATHS | 1980-11-17 | TGT | F | 24500 |
+----+----------+-------+------------+----------+--------+--------+
7 rows in set (0.00 sec)
mysql> SELECT COUNT()FROM TEACHERS WHERE DEBT="ENG";
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 ')FROM TEACHERS WHERE DEBT="ENG"' at line 1
mysql> SELECT COUNT("DEBT")FROM TEACHERS WHERE DEBT="ENG";
+---------------+
| COUNT("DEBT") |
+---------------+
| 2 |
+---------------+
1 row in set (0.01 sec)
mysql> SELECT COUNT("ENG")FROM TEACHERS WHERE DEBT="ENG";
+--------------+
| COUNT("ENG") |
+--------------+
| 2 |
+--------------+
1 row in set (0.00 sec)
mysql> SELECT COUNT("ENG")FROM TEACHERS WHERE DEBT="ENG";
Comments