You are on page 1of 14

nivya@nivya-Lenovo-G580:~$ mysql -u root -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2019, 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> use databases;


ERROR 1049 (42000): Unknown database 'databases'
mysql> use database;
ERROR 1049 (42000): Unknown database 'database'
mysql> use databases;
ERROR 1049 (42000): Unknown database 'databases'
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| LIBRARY |
| SCHOOL |
| events |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
8 rows in set (0.36 sec)

mysql> use SCHOOL;


Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+------------------+
| Tables_in_SCHOOL |
+------------------+
| EMPLOYEE |
| student |
+------------------+
2 rows in set (0.00 sec)

mysql> A+B=10
-> EXIT
->
-> ;
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 'A+B=10
EXIT' at line 1
mysql> SELECT A+B
-> 10+20;
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 '10+20' at line 2
mysql> SELECT A+B 10+20
-> ;
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 '10+20' at line 1
mysql> SELECT 20+30;
+-------+
| 20+30 |
+-------+
| 50 |
+-------+
1 row in set (0.00 sec)

mysql> SELECT 20-30;


+-------+
| 20-30 |
+-------+
| -10 |
+-------+
1 row in set (0.00 sec)

mysql> SELECT 2*5;


+-----+
| 2*5 |
+-----+
| 10 |
+-----+
1 row in set (0.00 sec)

mysql> SELECT 20/5;


+--------+
| 20/5 |
+--------+
| 4.0000 |
+--------+
1 row in set (0.00 sec)

mysql> SELECT 20%5;


+------+
| 20%5 |
+------+
| 0|
+------+
1 row in set (0.00 sec)
mysql> SELECT * FROM student where s_id=11;
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
+------+--------+-------+
2 rows in set (0.00 sec)

mysql> select * from student


-> ;
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
+------+--------+-------+
4 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id=10;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> SELECT * FROM student where s_name=abc;


ERROR 1054 (42S22): Unknown column 'abc' in 'where clause'
mysql> SELECT * FROM student where s_name='abc';
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 20 | abc | 19 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> insert into student values(101,"xyz",56);


Query OK, 1 row affected (0.34 sec)

mysql> select * from student;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
+------+--------+-------+
5 rows in set (0.00 sec)

mysql> insert into student values(103,"Anil",56);


Query OK, 1 row affected (0.10 sec)

mysql> insert into student values(106,"Anand",16);


Query OK, 1 row affected (0.35 sec)

mysql> select * from student;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id>103;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 106 | Anand | 16 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> SELECT * FROM student where s_id<103;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
+------+--------+-------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id>=101;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM student where s_id<=100;
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
+------+--------+-------+
4 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id<>101;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
6 rows in set (0.00 sec)

mysql> select s_id from student where s_id>100;


+------+
| s_id |
+------+
| 101 |
| 103 |
| 106 |
+------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id=10 AND s_name='abc';


Empty set (0.00 sec)

mysql> SELECT * FROM student where s_id=10 AND s_name='devraj';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> SELECT * FROM student where s_id=10 OR s_name='devraj';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)
mysql> SELECT * FROM student where s_id=10 OR s_name='abc';
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
+------+--------+-------+
2 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id=10 OR s_name='fhgdfc';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> SELECT * FROM student where s_id=1550 OR s_name='fhgdfc';


Empty set (0.00 sec)

mysql> SELECT * FROM student where s_id<ANY;


ERROR 1054 (42S22): Unknown column 'ANY' in 'where clause'
mysql> SELECT * FROM student where s_id>ANY;
ERROR 1054 (42S22): Unknown column 'ANY' in 'where clause'
mysql> SELECT * FROM student where s_id<20;
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
+------+--------+-------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id=20;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 20 | abc | 19 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> SELECT * FROM student where s_id<20;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
+------+--------+-------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM student where s_id>200;
Empty set (0.00 sec)

mysql> SELECT * FROM student where s_id>20;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id>20;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
3 rows in set (0.00 sec)

mysql> select * from student;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id<>50;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)
mysql> SELECT * FROM student where s_id BETWEEN 10 AND 20;
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
+------+--------+-------+
4 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_id BETWEEN 10 OR 20;


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 'OR 20' at line 1
mysql> SELECT * FROM student where s_id BETWEEN 10 OR 20;
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 'OR 20' at line 1
mysql> SELECT * FROM student where s_id BETWEEN 10 OR 200;
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 'OR 200' at line 1
mysql> SELECT * FROM student where s_id BETWEEN 10 OR 20;
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 'OR 20' at line 1
mysql> SELECT * FROM student where s_name BETWEEN 'tt7f' OR 'XYZ';
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 'OR 'XYZ'' at line 1
mysql> SELECT * FROM student where s_name BETWEEN 'tt7f' AND 'XYZ';
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
+------+--------+-------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM student where s_name BETWEEN 'tt7f' AND 'XYZ';
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
+------+--------+-------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM student;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)

mysql> select * from student where s_age BETWEEN 10 AND 60;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
5 rows in set (0.00 sec)

mysql> select * from student where s_id IN (10,1);


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> select * from student where s_id IN (10,10);


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> select * from student where s_id IN (10);


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.01 sec)

mysql> select * from student where s_id IN (100);


Empty set (0.00 sec)

mysql> select * from student where s_id IN (100;


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 1
mysql> select * from student where s_id IN (100);
Empty set (0.00 sec)
mysql> select * from student where s_age IN 29;
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 '29' at line 1
mysql> select * from student where s_age IN (29);
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> select * from student where s_age in (29);


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> select * from student where s_age between 10 and 60;


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
5 rows in set (0.00 sec)

mysql> select * from student where s_age in (29);


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> select * from student where s_name LIKE 'a%';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 20 | abc | 19 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
3 rows in set (0.00 sec)

mysql> select * from student where s_name LIKE 20;


Empty set (0.00 sec)
mysql> select * from student where s_name LIKE '20%';
Empty set (0.00 sec)

mysql> select * from student where s_name LIKE 'a%';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 20 | abc | 19 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
3 rows in set (0.00 sec)

mysql> select * from student where s_name LIKE 'x%';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 101 | xyz | 56 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> select * from student where s_name LIKE 'n%';


Empty set (0.00 sec)

mysql> select * from student where s_name LIKE '%d';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 106 | Anand | 16 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> select * from student where s_name LIKE 'd%';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
+------+--------+-------+
1 row in set (0.00 sec)

mysql> select * from student where s_name NOTLIKE 'n%';


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 'NOTLIKE 'n%'' at line 1
mysql> select * from student where s_name NOT LIKE 'n%';
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)

mysql> select * from student where s_name LIKE 'n%';


Empty set (0.00 sec)

mysql> select * from student where s_name NOT LIKE 'n%';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)

mysql> select * from student where s_name NOT LIKE 'a%';


+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
+------+--------+-------+
4 rows in set (0.00 sec)

mysql> select * from student where exists(select s_id from student where s_name='abc');
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)

mysql> select * from student where exists(select s_id from student where s_age=56);
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)

mysql> select * from student where exists(selectes_id from student where s_age=56);
[1]+ Stopped mysql -u root -p
nivya@nivya-Lenovo-G580:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2019, 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 |
| LIBRARY |
| SCHOOL |
| events |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
8 rows in set (0.01 sec)

mysql> use SCHOOL;


Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from student where exists(selectes_id from student where s_age=56);
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 'selectes_id from student where
s_age=56)' at line 1
mysql> select * from student where exists(selecte e_id from student where s_age=56);
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 'selecte e_id from student where
s_age=56)' at line 1
mysql> select * from student where exists(select e_id from student where s_age=56);
ERROR 1054 (42S22): Unknown column 'e_id' in 'field list'
mysql> select * from student where exists(select s_name from student where s_age=56);
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 101 | xyz | 56 |
| 103 | Anil | 56 |
| 106 | Anand | 16 |
+------+--------+-------+
7 rows in set (0.00 sec)

mysql> devarajmt.ece@gmail.com

You might also like