Professional Documents
Culture Documents
Sahil 7-9
Sahil 7-9
Sahil 7-9
A common use of subqueries is to perform tests for set membership, set comparisons, and set cardinality.
Example 1: - Find all the customer_id and customer_name who belongs to same city by fetching data from 2
different tables.
Syntax: select customer_id, customer_name from borrower where customer_id in (select customer_id from
customer where city = ‘Hamirpur’);
Example 2: - Find all customers who belongs to same city by fetching data from same table.
Page | 37
Syntax: select customer_id, customer_name, street from customer where customer_id in (select customer_id
from customer where city=’Hamirpur’);
Page | 38
EXPERIMENT NO: - 08
Delete single: we can delete a single record in a table using where clause with delete command.
Page | 39
Delete Multiple: We can delete multiple records by using in, and, or operators with delete command.
Syntax: DELETE FROM <table_name> WHERE <column_name> IN (value 1, value 2, value 3, etc...);
Example: delete from customer where customer_name in (‘Disha’, ’Raghav Soni’, ’Shruti’);
Delete All: To delete all the records in a table use truncate command.
Page | 40
EXPERIMENT NO: - 09
Dropping table that has primary key: To drop table a table that has primary key in it, just simply use MySQL
drop command. Make sure that the table to be deleted is not referenced by any other table.
Dropping table that has foreign key:To drop a table that has foreign key in it, just simply use MySQL drop
command. Make sure that the table to be deleted is not referenced by any other table.
Page | 41
Syntax: drop table <table_name>;
Page | 42