0% found this document useful (0 votes)
8 views

SQL CLASS2

Uploaded by

mohit.g
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL CLASS2

Uploaded by

mohit.g
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

mysql> show database abcd;

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

mysql> show databases;

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

| Database |

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

| abcd |

| information_schema |

| mysql |

| performance_schema |

| sakila |

| sys |

| world |

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

7 rows in set (0.02 sec)

mysql> use abcd;

Database changed

mysql> show tables;

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

| Tables_in_abcd |

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

| customer |

| orders |

| person3 |

| person4 |

| person5 |

| persons |

| persons1 |

+----------------+
7 rows in set (0.01 sec)

mysql> describe customer;

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

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

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

| CustID | int | NO | PRI | NULL | |

| CustName | varchar(255) | NO | | NULL | |

| ContactNo | varchar(255) | NO | | NULL | |

| Address | varchar(255) | NO | | NULL | |

| City | varchar(255) | NO | | NULL | |

| Pincode | int | NO | | NULL | |

| Country | varchar(255) | NO | | NULL | |

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

7 rows in set (0.01 sec)

mysql> select * from customer;

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 1 | Arushi | 9540796636 | Dwarka | New Delhi | 110075 | India |

| 2 | Akshay | 9540796637 | Chembur | Maharastra | 400089 | India |

| 3 | Aditi | 9440796637 | SS | Kolkata | 100089 | India |

| 4 | Divyanshu | 9448796637 | Mayur Vihar | East Delhi | 100079 | India |

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

4 rows in set (0.03 sec)

mysql> select custname, City, Country from customers;

ERROR 1146 (42S02): Table 'abcd.customers' doesn't exist

mysql> select custname, City, Country from customer;

+-----------+------------+---------+
| custname | City | Country |

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

| Arushi | New Delhi | India |

| Akshay | Maharastra | India |

| Aditi | Kolkata | India |

| Divyanshu | East Delhi | India |

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

4 rows in set (0.00 sec)

mysql> select * from customers where city="New Delhi";

ERROR 1146 (42S02): Table 'abcd.customers' doesn't exist

mysql> select * from customer where city="New Delhi";

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 1 | Arushi | 9540796636 | Dwarka | New Delhi | 110075 | India |

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

1 row in set (0.01 sec)

mysql> Insert into Customer Values("5", "Mohit", "9448886637","Sant Nagar","Ujjain", "100099",


"India");

Query OK, 1 row affected (0.01 sec)

mysql> Insert into Customer Values("6", "Rhiti", "9448886637","Brooklyn","Ottawa", "100099",


"Canada");

Query OK, 1 row affected (0.01 sec)

mysql> select * from customers;

ERROR 1146 (42S02): Table 'abcd.customers' doesn't exist

mysql> select * from customer;

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |


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

| 1 | Arushi | 9540796636 | Dwarka | New Delhi | 110075 | India |

| 2 | Akshay | 9540796637 | Chembur | Maharastra | 400089 | India |

| 3 | Aditi | 9440796637 | SS | Kolkata | 100089 | India |

| 4 | Divyanshu | 9448796637 | Mayur Vihar | East Delhi | 100079 | India |

| 5 | Mohit | 9448886637 | Sant Nagar | Ujjain | 100099 | India |

| 6 | Rhiti | 9448886637 | Brooklyn | Ottawa | 100099 | Canada |

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

6 rows in set (0.00 sec)

mysql> select * from customer where custId="3";

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 3 | Aditi | 9440796637 | SS | Kolkata | 100089 | India |

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

1 row in set (0.00 sec)

mysql> create table product (p_code, pname varchar(255), price int, manufacturer varchar(255),
primary key(p_code));

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 ', pname varchar(255), price int,
manufacturer varchar(255), primary key(p_code))' at line 1

mysql> create table product (p_code int,pname varchar(255),price int,manufacturer


varchar(255),primary key(p_code));

Query OK, 0 rows affected (0.03 sec)

mysql> Insert into product Values("1", "laptop","30000","Dell");

Query OK, 1 row affected (0.01 sec)

mysql> Insert into product Values("2", "laptop","35000","HP");

Query OK, 1 row affected (0.01 sec)


mysql> Insert into product Values("3", "Phone","35000","Samsung");

Query OK, 1 row affected (0.01 sec)

mysql> Insert into product Values("3", "Printer","20000","HP");

ERROR 1062 (23000): Duplicate entry '3' for key 'product.PRIMARY'

mysql> Insert into product Values("4", "Printer","20000","HP");

Query OK, 1 row affected (0.01 sec)

mysql> Insert into product Values("5", "Phone","20000","Xaomi");

Query OK, 1 row affected (0.01 sec)

mysql> select * from products;

ERROR 1146 (42S02): Table 'abcd.products' doesn't exist

mysql> select * product;

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

mysql> select * from product;

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

| p_code | pname | price | manufacturer |

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

| 1 | laptop | 30000 | Dell |

| 2 | laptop | 35000 | HP |

| 3 | Phone | 35000 | Samsung |

| 4 | Printer | 20000 | HP |

| 5 | Phone | 20000 | Xaomi |

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

5 rows in set (0.00 sec)

mysql> select * from product where price=30000;

+--------+--------+-------+--------------+
| p_code | pname | price | manufacturer |

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

| 1 | laptop | 30000 | Dell |

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

1 row in set (0.00 sec)

mysql> select pname from product where price=20000;

+---------+

| pname |

+---------+

| Printer |

| Phone |

+---------+

2 rows in set (0.00 sec)

mysql> select * from product where Price between 10000 and 30000;

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

| p_code | pname | price | manufacturer |

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

| 1 | laptop | 30000 | Dell |

| 4 | Printer | 20000 | HP |

| 5 | Phone | 20000 | Xaomi |

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

3 rows in set (0.01 sec)

mysql> select * from customer where city like 'E%';

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 4 | Divyanshu | 9448796637 | Mayur Vihar | East Delhi | 100079 | India |

+--------+-----------+------------+-------------+------------+---------+---------+
1 row in set (0.00 sec)

mysql> select * from product where pname like 'l%';

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

| p_code | pname | price | manufacturer |

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

| 1 | laptop | 30000 | Dell |

| 2 | laptop | 35000 | HP |

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

2 rows in set (0.00 sec)

mysql> select * from product where price=20000 and 30000;

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

| p_code | pname | price | manufacturer |

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

| 4 | Printer | 20000 | HP |

| 5 | Phone | 20000 | Xaomi |

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

2 rows in set (0.00 sec)

mysql> select * from product where price=20000 and price=30000;

Empty set (0.00 sec)

mysql> select * from product where pname like 'l%' and 'p%';

Empty set, 1 warning (0.00 sec)

mysql> select * from product where pname like 'l%' and like 'p%';

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 'like 'p%'' at line 1

mysql> select * from product where pname like 'l%', like'p%';

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 ', like'p%'' at line 1
mysql> select * from product where pname like 'l%','p%';

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 ','p%'' at line 1

mysql> select * from customers where city in('Canada');

ERROR 1146 (42S02): Table 'abcd.customers' doesn't exist

mysql> select * from customer where city in('Canada');

Empty set (0.00 sec)

mysql> select * from customer where country in('Canada');

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 6 | Rhiti | 9448886637 | Brooklyn | Ottawa | 100099 | Canada |

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

1 row in set (0.00 sec)

mysql> select * from customer order by Country;

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 6 | Rhiti | 9448886637 | Brooklyn | Ottawa | 100099 | Canada |

| 1 | Arushi | 9540796636 | Dwarka | New Delhi | 110075 | India |

| 2 | Akshay | 9540796637 | Chembur | Maharastra | 400089 | India |

| 3 | Aditi | 9440796637 | SS | Kolkata | 100089 | India |

| 4 | Divyanshu | 9448796637 | Mayur Vihar | East Delhi | 100079 | India |

| 5 | Mohit | 9448886637 | Sant Nagar | Ujjain | 100099 | India |

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

6 rows in set (0.01 sec)

mysql> select * from customer order by Country DESC;

+--------+-----------+------------+-------------+------------+---------+---------+
| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 1 | Arushi | 9540796636 | Dwarka | New Delhi | 110075 | India |

| 2 | Akshay | 9540796637 | Chembur | Maharastra | 400089 | India |

| 3 | Aditi | 9440796637 | SS | Kolkata | 100089 | India |

| 4 | Divyanshu | 9448796637 | Mayur Vihar | East Delhi | 100079 | India |

| 5 | Mohit | 9448886637 | Sant Nagar | Ujjain | 100099 | India |

| 6 | Rhiti | 9448886637 | Brooklyn | Ottawa | 100099 | Canada |

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

6 rows in set (0.00 sec)

mysql> Update customer set contactno="9540796676", city="Mumbai" where custid=1;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from customer;

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 1 | Arushi | 9540796676 | Dwarka | Mumbai | 110075 | India |

| 2 | Akshay | 9540796637 | Chembur | Maharastra | 400089 | India |

| 3 | Aditi | 9440796637 | SS | Kolkata | 100089 | India |

| 4 | Divyanshu | 9448796637 | Mayur Vihar | East Delhi | 100079 | India |

| 5 | Mohit | 9448886637 | Sant Nagar | Ujjain | 100099 | India |

| 6 | Rhiti | 9448886637 | Brooklyn | Ottawa | 100099 | Canada |

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

6 rows in set (0.00 sec)

mysql> update customer set postal code= 110075 where city="East Delhi";

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 'code= 110075 where city="East Delhi"' at
line 1
mysql> update customer set pincode= 110075 where city="East Delhi";

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from customers;

ERROR 1146 (42S02): Table 'abcd.customers' doesn't exist

mysql> select * from customer;

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 1 | Arushi | 9540796676 | Dwarka | Mumbai | 110075 | India |

| 2 | Akshay | 9540796637 | Chembur | Maharastra | 400089 | India |

| 3 | Aditi | 9440796637 | SS | Kolkata | 100089 | India |

| 4 | Divyanshu | 9448796637 | Mayur Vihar | East Delhi | 110075 | India |

| 5 | Mohit | 9448886637 | Sant Nagar | Ujjain | 100099 | India |

| 6 | Rhiti | 9448886637 | Brooklyn | Ottawa | 100099 | Canada |

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

6 rows in set (0.00 sec)

mysql> delete from customers where custname="Akshay";

ERROR 1146 (42S02): Table 'abcd.customers' doesn't exist

mysql> delete from customer where custname="Akshay";

Query OK, 1 row affected (0.01 sec)

mysql> select * from customer;

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

| CustID | CustName | ContactNo | Address | City | Pincode | Country |

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

| 1 | Arushi | 9540796676 | Dwarka | Mumbai | 110075 | India |

| 3 | Aditi | 9440796637 | SS | Kolkata | 100089 | India |

| 4 | Divyanshu | 9448796637 | Mayur Vihar | East Delhi | 110075 | India |


| 5 | Mohit | 9448886637 | Sant Nagar | Ujjain | 100099 | India |

| 6 | Rhiti | 9448886637 | Brooklyn | Ottawa | 100099 | Canada |

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

5 rows in set (0.00 sec)

mysql> select min(price) as smallestprice;

ERROR 1054 (42S22): Unknown column 'price' in 'field list'

mysql> select min(price) as smallest_price;

ERROR 1054 (42S22): Unknown column 'price' in 'field list'

mysql> select min(price) as smallest_price from product;

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

| smallest_price |

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

| 20000 |

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

1 row in set (0.01 sec)

mysql> select max(price) as max_price from product;

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

| max_price |

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

| 35000 |

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

1 row in set (0.00 sec)

mysql> select count(p_code);

ERROR 1054 (42S22): Unknown column 'p_code' in 'field list'

mysql> select count(p_code) from products;

ERROR 1146 (42S02): Table 'abcd.products' doesn't exist

mysql> select count(p_code) from product;

+---------------+
| count(p_code) |

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

| 5|

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

1 row in set (0.00 sec)

mysql> select count distinct(custname) from customer;

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 'distinct(custname) from customer' at line
1

mysql> select count (distinct custname) from customer;

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 'distinct custname) from customer' at line
1

mysql> select count(distinct country) from customer;

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

| count(distinct country) |

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

| 2|

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

1 row in set (0.01 sec)

mysql> select avg(price) from products;

ERROR 1146 (42S02): Table 'abcd.products' doesn't exist

mysql> select avg(price) from product;

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

| avg(price) |

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

| 28000.0000 |

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

1 row in set (0.00 sec)


mysql> select sum(price) from product;

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

| sum(price) |

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

| 140000 |

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

1 row in set (0.00 sec)

mysql> create table orders;

ERROR 4028 (HY000): A table must have at least one visible column.

mysql> create table orders( orderID int, CustID int, orderDate date);

ERROR 1050 (42S01): Table 'orders' already exists

mysql> select * from orders;

Empty set (0.02 sec)

mysql> create table order( orderID int, CustID int, orderDate date);

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 'order( orderID int, CustID int, orderDate
date)' at line 1

mysql> create table order (orderID int, CustID int, orderDate date);

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 'order (orderID int, CustID int, orderDate
date)' at line 1

mysql> create table order(orderID int, CustID int, orderDate date);

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 'order(orderID int, CustID int, orderDate
date)' at line 1

mysql> create table order(orderID int, CustID int, orderDate date);

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 'order(orderID int, CustID int, orderDate
date)' at line 1

mysql> INSERT INTO Orders1 (orderid, custid, orderdate)

-> -> VALUES

-> -> (101, 1, '2024-11-01'), -- Order by John Doe


-> -> (102, 2, '2024-11-02'), -- Order by Jane Smith

-> -> (103, 3, '2024-11-03'), -- Order by Amit Kumar

-> -> (104, 4, '2024-11-04'), -- Order by Chen Wei

-> -> (105, 5, '2024-11-05'), -- Order by Maria Lopez

-> -> (106, 6, '2024-11-06'), -- Order by Ahmed Ali

-> -> (107, 7, '2024-11-07'), -- Order by Emily Brown

-> -> (108, 8, '2024-11-08'), -- Order by Carlos Silva

-> -> (109, 9, '2024-11-09'), -- Order by Satoshi Tanaka

-> -> (110, 10, '2024-11-10'); -- Order by Fatima Noor;

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

-> (101, 1, '2024-11-01'),

-> (102, 2, '2024-11-02'),

' at line 2

mysql> create table Order(orderid int, custid int, orderdate);

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 'Order(orderid int, custid int, orderdate)'
at line 1

mysql> create table orders(orderID int, CustomerID int, OrderDate int);

ERROR 1050 (42S01): Table 'orders' already exists

mysql> ^C

mysql> create table orders(orderID int, CustomerID int, OrderDate date);

ERROR 1050 (42S01): Table 'orders' already exists

mysql> create table order1(orderID int, CustomerID int, OrderDate date);

Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO Orders1 (orderid, custid, orderdate)

-> -> -> VALUES

-> -> -> (101, 1, '2024-11-01'), -- Order by John Doe

-> -> -> (102, 2, '2024-11-02'), -- Order by Jane Smith

-> -> -> (103, 3, '2024-11-03'), -- Order by Amit Kumar

-> -> -> (104, 4, '2024-11-04'), -- Order by Chen Wei


-> -> -> (105, 5, '2024-11-05'), -- Order by Maria Lopez

-> -> -> (106, 6, '2024-11-06'), -- Order by Ahmed Ali

-> -> -> (107, 7, '2024-11-07'), -- Order by Emily Brown

-> -> -> (108, 8, '2024-11-08'), -- Order by Carlos Silva

-> -> -> (109, 9, '2024-11-09'), -- Order by Satoshi Tanaka

-> ;

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

-> -> (101, 1, '2024-11-01'),

-> -> (102, 2, ' at line 2

mysql> INSERT INTO Orders1 (orderid, custid, orderdate) values(101, 1, '2024-11-01');

ERROR 1146 (42S02): Table 'abcd.orders1' doesn't exist

mysql> INSERT INTO Order1 (orderid, custid, orderdate) values(101, 1, '2024-11-01');

ERROR 1054 (42S22): Unknown column 'custid' in 'field list'

mysql> INSERT INTO Order1 (orderid, customerid, orderdate) values(101, 1, '2024-11-01');

Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO Order1 (orderid, custid, orderdate) values (102, 2, '2024-11-02'),(103, 3, '2024-
11-03');

ERROR 1054 (42S22): Unknown column 'custid' in 'field list'

mysql> INSERT INTO Order1 (orderid, customerid, orderdate) values (102, 2, '2024-11-02'),(103, 3,
'2024-11-03');

Query OK, 2 rows affected (0.00 sec)

Records: 2 Duplicates: 0 Warnings: 0

mysql>

You might also like