Exp 7
Exp 7
[NBA Accredited]
EXPERIMENT 7
In nested queries, a query is written inside a query. The result of inner query is used in execution
Theory: of outer query.
A query is usually added within the WHERE Clause of another SELECT query.
The comparison operators, including >, <, or = can be used. The comparison operator can also be
a operator which is used in more than one row, such as IN, ANY, SOME, or ALL.
A nested query can be treated as an inner query, which is a SQL query placed as a part of another
query called as outer query.
The inner query is executed first and then the outer query so that the results of the inner query can
be used by the outer query.
Example:
SELECT employee_id,first_name,last_name,salary
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the LIKE operator:
Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE
clause to search for a specified pattern in a column.
The following SQL statement selects all customers with a City starting with "b", "s", or
"p"
The following SQL statement selects all customers with a City starting with "a", "b", or "c":
The two following SQL statements select all customers with a City NOT starting with "b", "s", or
"p":
Table Actor
Table Director
Directs
1. Find name of the director/s for all the movies with HIT status.
4. List maximum and average budget and number of movies for the movies for each
Production.
5. List all the movies releases in the 1990’s decade ie all the movies with year release 199* ,
where * could be nay number from 1 to 9.
6. List all the movies with title that includes word ‘Khiladi’.
8. Find the name/s of the director who took more than average days to direct a movie.
use demo;
Title varchar(100),
Genre varchar(100),
Year int,
Budget int,
Hit_Status varchar(100),
Production_Name varchar(100),
);
describe movie;
Dname varchar(100) ,
Gender CHAR,
);
A_name varchar(100),
Gender char,
);
describe actor;
Role varchar(100),
Fees int,
PRIMARY KEY(Movie_id,A_id),
);
desc acts;
update acts
No_of_Days int,
PRIMARY KEY(D_id,Movie_id),
);
/* 1.Find name of the director/s for all the movies with HIT status*/
from directs as d join movie as m on d.movie_id =m.movie_id join director as dc on dc.did = d. d_id
from directs as d join movie as m on d.movie_id =m.movie_id join director as dc on dc.did = d. d_id
from actor a join acts ac on a. a_id = ac.a_id join movie m on m. movie_id = ac. movie_id
where fees = (
select max(fees)
from acts );
/* 4. List maximum and average budget and number of movies for the movies for each Production.*/
from movie
/* 5. List all the movies releases in the 2000’s decade ie all the movies with year release 200* , where * could be
nay number from 1 to 9. */
Select title
from movie
/* 6. List all the movies with title that includes word ‘khiladi’ */
select title
from movie
/*7. List all the movies with genre that includes drama*/
select title
from movie
/* 8. Find the name/s of the director who took more than average days to direct a movie. */
from director d join directs dr on d.did = dr.d_id join movie m on m. movie_id = dr.movie_id
select avg(no_of_days)
from directs; );