lecture 5
lecture 5
SELECT *
FROM customer
WHERE age = (
SELECT MIN(age)
FROM Customers
);
2
1. Subqueries with the Select
Statement
SELECT *
FROM customer
where salary>=4500
SELECT *
FROM customer
WHERE cid IN (SELECT cid FROM customer WHERE
SALARY >= 4500);
3
2. Subqueries with the INSERT
Statement
SQL subquery can also be used with the Insert
statement. In the insert statement, data returned from
the subquery is used to insert into another table.
4
3. Subqueries with the UPDATE
Statement
The given example updates the SALARY by .25 times in
the customer table for all customers whose AGE is
greater than or equal to 29.
UPDATE customer
SET salary = salary * 0.25
WHERE age IN (SELECT age FROM customer
WHERE age >= 29);
5
4. Subqueries with the DELETE
Statement
The given example deletes the records from the
customer table for all customer whose AGE is greater
than or equal to 29.
6
SQL INNER JOIN
The SQL INNER JOIN statement joins two tables
based on a common column and selects rows that have
matching values in these columns.
7
Example: Join Two Table Based on
Common Column
-- join Customers and Orders tables based on -- cid of
customer and oid column of Orders
8
SQL CROSS JOIN
In SQL, the CROSS JOIN operation allows us to
combine rows from two or more tables without any
specific relationship between them.
Example
SELECT *
FROM student, teacher
9
Query to fill all columns at a time
UPDATE student SET address = 'khulna‘ WHERE 1>0;
10