You are on page 1of 8

mysql> use banking;

Database changed

mysql> select cust_id from depositor union all select cust_id from borrower;

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

| cust_id |

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

| 192-83-7465 |

| 677-89-9011 |

| 019-28-3746 |

| 192-83-7465 |

| 019-28-3746 |

| 321-12-3123 |

| 336-66-9999 |

| 182-73-6091 |

| 019-28-3746 |

| 192-83-7465 |

| 677-89-9011 |

| 335-57-7991 |

| 321-12-3123 |

| 963-96-3963 |

| 244-66-8800 |

| 019-28-3746 |

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

16 rows in set (0.02 sec)

mysql> select cust_id from depositor union select cust_id from borrower;

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

| cust_id |

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

| 192-83-7465 |
| 677-89-9011 |

| 019-28-3746 |

| 321-12-3123 |

| 336-66-9999 |

| 182-73-6091 |

| 335-57-7991 |

| 963-96-3963 |

| 244-66-8800 |

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

9 rows in set (0.00 sec)

mysql> select cust_id from depositor union all select cust_id from borrower;

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

| cust_id |

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

| 192-83-7465 |

| 677-89-9011 |

| 019-28-3746 |

| 192-83-7465 |

| 019-28-3746 |

| 321-12-3123 |

| 336-66-9999 |

| 182-73-6091 |

| 019-28-3746 |

| 192-83-7465 |

| 677-89-9011 |

| 335-57-7991 |

| 321-12-3123 |

| 963-96-3963 |

| 244-66-8800 |

| 019-28-3746 |
+-------------+

16 rows in set (0.00 sec)

mysql> select cust_id from depositor where cust_id in (select cust_id from borrower);

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

| cust_id |

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

| 192-83-7465 |

| 677-89-9011 |

| 019-28-3746 |

| 192-83-7465 |

| 019-28-3746 |

| 321-12-3123 |

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

6 rows in set (0.00 sec)

mysql> select cust_id from depositor where cust_id not in (select cust_id from borrower);

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

| cust_id |

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

| 336-66-9999 |

| 182-73-6091 |

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

2 rows in set (0.00 sec)

mysql> select cust_name from customer, depositor where depositor.cust_id=customer.cust_id and


depositor.cust_id in (select cust_id from borrower);

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

| cust_name |

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

| Johnson |
| Hayes |

| Smith |

| Johnson |

| Smith |

| Jones |

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

6 rows in set (0.01 sec)

mysql> select cust_name from customer, depositor where depositor.cust_id=customer.cust_id and


depositor.cust_id not in (select cust_id from borrower);

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

| cust_name |

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

| Lindsay |

| Turner |

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

2 rows in set (0.00 sec)

mysql> select distinct depositor.cust_id from depositor, borrower where depositor.cust_id !=


borrower.cust_id;

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

| cust_id |

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

| 192-83-7465 |

| 677-89-9011 |

| 321-12-3123 |

| 336-66-9999 |

| 182-73-6091 |

| 019-28-3746 |

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

6 rows in set (0.01 sec)


mysql> select * from branch;

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

| branch_name | branch_city | assets |

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

| Brighton | Brooklyn | 7100000 |

| Downtown | Brooklyn | 9000000 |

| Mianus | Horseneck | 400000 |

| North Town | Rye | 3700000 |

| Perryridge | Horseneck | 1700000 |

| Pownal | Bennington | 300000 |

| Redwood | Palo Alto | 2100000 |

| Round Hill | Horseneck | 8000000 |

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

8 rows in set (0.01 sec)

mysql> select sum(assets) from branch;

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

| sum(assets) |

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

| 32300000 |

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

1 row in set (0.00 sec)

mysql> select sum(assets) as total_sum from branch;

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

| total_sum |

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

| 32300000 |

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

1 row in set (0.00 sec)


mysql> update branch set assets=NULL where branch_name='Brighton';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from branch;

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

| branch_name | branch_city | assets |

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

| Brighton | Brooklyn | NULL |

| Downtown | Brooklyn | 9000000 |

| Mianus | Horseneck | 400000 |

| North Town | Rye | 3700000 |

| Perryridge | Horseneck | 1700000 |

| Pownal | Bennington | 300000 |

| Redwood | Palo Alto | 2100000 |

| Round Hill | Horseneck | 8000000 |

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

8 rows in set (0.00 sec)

mysql> select count(*) from branch;

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

| count(*) |

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

| 8|

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

1 row in set (0.01 sec)

mysql> select count(assets) from branch;

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

| count(assets) |

+---------------+
| 7|

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

1 row in set (0.00 sec)

mysql> create table abc(

-> salary int,

-> name varchar(10));

Query OK, 0 rows affected (0.32 sec)

mysql> insert into abc values(1000,'Teena'),(2000,'Meena');

Query OK, 2 rows affected (0.02 sec)

Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from abc;

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

| salary | name |

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

| 1000 | Teena |

| 2000 | Meena |

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

2 rows in set (0.00 sec)

mysql> update abc set name=NULL where salary=1000;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> update abc set salary=NULL where salary=1000;

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from abc;


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

| salary | name |

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

| NULL | NULL |

| 2000 | Meena |

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

2 rows in set (0.01 sec)

mysql> select count(*) from abc;

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

| count(*) |

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

| 2|

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

1 row in set (0.00 sec)

mysql> select count(salary) from abc;

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

| count(salary) |

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

| 1|

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

1 row in set (0.00 sec)

mysql> select count(branch_name), count(assets) from branch;

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

| count(branch_name) | count(assets) |

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

| 8| 7|

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

1 row in set (0.01 sec)

You might also like