0% found this document useful (0 votes)
7 views11 pages

SQL Queries

SQL

Uploaded by

nsbagheldatiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

SQL Queries

SQL

Uploaded by

nsbagheldatiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

SQL QUERIES

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 9.1.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, 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 |

+--------------------+

| information_schema |

| kvs |

| mysql |

| performance_schema |

| sys |

+--------------------+

5 rows in set (0.13 sec)

mysql> show database kvs;


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 'database kvs' at line 1

mysql> use kvs;

Database changed

mysql> desc cs11;

+---------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+---------+-------------+------+-----+---------+-------+

| Roll_no | int | YES | | NULL | |

| Name | varchar(25) | YES | | NULL | |

| Address | varchar(25) | YES | | NULL | |

| mobile | int | YES | | NULL | |

+---------+-------------+------+-----+---------+-------+

4 rows in set (0.18 sec)

mysql> show tables;

+---------------+

| Tables_in_kvs |

+---------------+

| cs11 |

+---------------+

1 row in set (0.05 sec)

mysql> select * from cs11;

+---------+------------+---------+-----------+

| Roll_no | Name | Address | mobile |

+---------+------------+---------+-----------+

| 11101 | Aayush Raj | Wadsar | 998877665 |

| 11102 | Anshu | Kalol | 888877665 |

+---------+------------+---------+-----------+

2 rows in set (0.02 sec)


mysql> insert into cs11 values(11113, "Rahul", "Wadsar", 989865654)

->

->

->

-> ^X

->

-> clear

->

-> insert into cs11 values(11113, "Rahul", "Wadsar", 989865654);

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 '↑

clear

insert into cs11 values(11113, "Rahul", "Wadsar", 989865654)' at line 5

mysql> insert into cs11 values(11113, "Rahul", "Wadsar", 989865654);

Query OK, 1 row affected (0.14 sec)

mysql> select * from cs11;

+---------+------------+---------+-----------+

| Roll_no | Name | Address | mobile |

+---------+------------+---------+-----------+

| 11101 | Aayush Raj | Wadsar | 998877665 |

| 11102 | Anshu | Kalol | 888877665 |

| 11113 | Rahul | Wadsar | 989865654 |

+---------+------------+---------+-----------+

3 rows in set (0.00 sec)

mysql> alter table cs11 add Subject varchar(25);

Query OK, 0 rows affected (0.56 sec)


Records: 0 Duplicates: 0 Warnings: 0

mysql> select * from cs11;

+---------+------------+---------+-----------+---------+

| Roll_no | Name | Address | mobile | Subject |

+---------+------------+---------+-----------+---------+

| 11101 | Aayush Raj | Wadsar | 998877665 | NULL |

| 11102 | Anshu | Kalol | 888877665 | NULL |

| 11113 | Rahul | Wadsar | 989865654 | NULL |

+---------+------------+---------+-----------+---------+

3 rows in set (0.00 sec)

mysql> update cs11 set Subject = "CS" where Roll_no = 11101;

Query OK, 1 row affected (0.08 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from cs11;

+---------+------------+---------+-----------+---------+

| Roll_no | Name | Address | mobile | Subject |

+---------+------------+---------+-----------+---------+

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11102 | Anshu | Kalol | 888877665 | NULL |

| 11113 | Rahul | Wadsar | 989865654 | NULL |

+---------+------------+---------+-----------+---------+

3 rows in set (0.00 sec)

mysql> update cs11 set Subject = "Maths" where Roll_no = 11102;

Query OK, 1 row affected (0.05 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from cs11;


+---------+------------+---------+-----------+---------+

| Roll_no | Name | Address | mobile | Subject |

+---------+------------+---------+-----------+---------+

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11113 | Rahul | Wadsar | 989865654 | NULL |

+---------+------------+---------+-----------+---------+

3 rows in set (0.00 sec)

mysql> update cs11 set Subject = "Chemistry" where Roll_no = 11113;

Query OK, 1 row affected (0.05 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from cs11;

+---------+------------+---------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+------------+---------+-----------+-----------+

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11113 | Rahul | Wadsar | 989865654 | Chemistry |

+---------+------------+---------+-----------+-----------+

3 rows in set (0.00 sec)

mysql> select Roll_no from cs11;

+---------+

| Roll_no |

+---------+

| 11101 |

| 11102 |

| 11113 |

+---------+
3 rows in set (0.00 sec)

mysql> select Roll_no, Name from cs11;

+---------+------------+

| Roll_no | Name |

+---------+------------+

| 11101 | Aayush Raj |

| 11102 | Anshu |

| 11113 | Rahul |

+---------+------------+

3 rows in set (0.00 sec)

mysql> select Roll_no, Name from cs11 where Subject = "CS";

+---------+------------+

| Roll_no | Name |

+---------+------------+

| 11101 | Aayush Raj |

+---------+------------+

1 row in set (0.01 sec)

mysql> insert into cs11 values(11112, "Piyush Raj", "Tata House", 456789123);

ERROR 1136 (21S01): Column count doesn't match value count at row 1

mysql> insert into cs11 values(11112, "Piyush Raj", "Tata House", 456789123, "Physics");

Query OK, 1 row affected (0.05 sec)

mysql> insert into cs11 values(11103, "Apeksha", "Wadsar", 776789123, "CS");

Query OK, 1 row affected (0.05 sec)

mysql> insert into cs11 values(11104, "Aayush Gupta", "Wadsar", 886789123, "Maths");

Query OK, 1 row affected (0.04 sec)


mysql> insert into cs11 values(11106, "madhvi", "Wadsar", 996789123, "Chemistry");

Query OK, 1 row affected (0.04 sec)

mysql> insert into cs11 values(11110, "Mohit", "Chandkheda", 986789123, "Physics");

Query OK, 1 row affected (0.05 sec)

mysql> select * from cs11;

+---------+--------------+------------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+--------------+------------+-----------+-----------+

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11113 | Rahul | Wadsar | 989865654 | Chemistry |

| 11112 | Piyush Raj | Tata House | 456789123 | Physics |

| 11103 | Apeksha | Wadsar | 776789123 | CS |

| 11104 | Aayush Gupta | Wadsar | 886789123 | Maths |

| 11106 | madhvi | Wadsar | 996789123 | Chemistry |

| 11110 | Mohit | Chandkheda | 986789123 | Physics |

+---------+--------------+------------+-----------+-----------+

8 rows in set (0.00 sec)

mysql> select * from cs11 order by Roll_no;

+---------+--------------+------------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+--------------+------------+-----------+-----------+

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11103 | Apeksha | Wadsar | 776789123 | CS |

| 11104 | Aayush Gupta | Wadsar | 886789123 | Maths |

| 11106 | madhvi | Wadsar | 996789123 | Chemistry |

| 11110 | Mohit | Chandkheda | 986789123 | Physics |


| 11112 | Piyush Raj | Tata House | 456789123 | Physics |

| 11113 | Rahul | Wadsar | 989865654 | Chemistry |

+---------+--------------+------------+-----------+-----------+

8 rows in set (0.00 sec)

mysql> select * from cs11 order by Roll_no desc;

+---------+--------------+------------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+--------------+------------+-----------+-----------+

| 11113 | Rahul | Wadsar | 989865654 | Chemistry |

| 11112 | Piyush Raj | Tata House | 456789123 | Physics |

| 11110 | Mohit | Chandkheda | 986789123 | Physics |

| 11106 | madhvi | Wadsar | 996789123 | Chemistry |

| 11104 | Aayush Gupta | Wadsar | 886789123 | Maths |

| 11103 | Apeksha | Wadsar | 776789123 | CS |

| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

+---------+--------------+------------+-----------+-----------+

8 rows in set (0.00 sec)

mysql> select * from cs11 order by Name;

+---------+--------------+------------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+--------------+------------+-----------+-----------+

| 11104 | Aayush Gupta | Wadsar | 886789123 | Maths |

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11103 | Apeksha | Wadsar | 776789123 | CS |

| 11106 | madhvi | Wadsar | 996789123 | Chemistry |

| 11110 | Mohit | Chandkheda | 986789123 | Physics |

| 11112 | Piyush Raj | Tata House | 456789123 | Physics |


| 11113 | Rahul | Wadsar | 989865654 | Chemistry |

+---------+--------------+------------+-----------+-----------+

8 rows in set (0.01 sec)

mysql> select * from cs11 order by Name desc;

+---------+--------------+------------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+--------------+------------+-----------+-----------+

| 11113 | Rahul | Wadsar | 989865654 | Chemistry |

| 11112 | Piyush Raj | Tata House | 456789123 | Physics |

| 11110 | Mohit | Chandkheda | 986789123 | Physics |

| 11106 | madhvi | Wadsar | 996789123 | Chemistry |

| 11103 | Apeksha | Wadsar | 776789123 | CS |

| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11104 | Aayush Gupta | Wadsar | 886789123 | Maths |

+---------+--------------+------------+-----------+-----------+

8 rows in set (0.00 sec)

mysql> select * from cs11 order by Address;

+---------+--------------+------------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+--------------+------------+-----------+-----------+

| 11110 | Mohit | Chandkheda | 986789123 | Physics |

| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11112 | Piyush Raj | Tata House | 456789123 | Physics |

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11113 | Rahul | Wadsar | 989865654 | Chemistry |

| 11103 | Apeksha | Wadsar | 776789123 | CS |

| 11104 | Aayush Gupta | Wadsar | 886789123 | Maths |

| 11106 | madhvi | Wadsar | 996789123 | Chemistry |


+---------+--------------+------------+-----------+-----------+

8 rows in set (0.00 sec)

mysql> select * from cs11 where city = "Wadsar";

ERROR 1054 (42S22): Unknown column 'city' in 'where clause'

mysql> select * from cs11 where Address = "Wadsar";

+---------+--------------+---------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+--------------+---------+-----------+-----------+

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11113 | Rahul | Wadsar | 989865654 | Chemistry |

| 11103 | Apeksha | Wadsar | 776789123 | CS |

| 11104 | Aayush Gupta | Wadsar | 886789123 | Maths |

| 11106 | madhvi | Wadsar | 996789123 | Chemistry |

+---------+--------------+---------+-----------+-----------+

5 rows in set (0.00 sec)

mysql> select * from cs11 where Roll_no in (11101,11110);

+---------+------------+------------+-----------+---------+

| Roll_no | Name | Address | mobile | Subject |

+---------+------------+------------+-----------+---------+

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |

| 11110 | Mohit | Chandkheda | 986789123 | Physics |

+---------+------------+------------+-----------+---------+

2 rows in set (0.00 sec)

mysql> select * from cs11 where Roll_no between 11101 and 11110;

+---------+--------------+------------+-----------+-----------+

| Roll_no | Name | Address | mobile | Subject |

+---------+--------------+------------+-----------+-----------+

| 11101 | Aayush Raj | Wadsar | 998877665 | CS |


| 11102 | Anshu | Kalol | 888877665 | Maths |

| 11103 | Apeksha | Wadsar | 776789123 | CS |

| 11104 | Aayush Gupta | Wadsar | 886789123 | Maths |

| 11106 | madhvi | Wadsar | 996789123 | Chemistry |

| 11110 | Mohit | Chandkheda | 986789123 | Physics |

+---------+--------------+------------+-----------+-----------+

6 rows in set (0.03 sec)

mysql>

You might also like