DEV Community

Lakshmi Pritha Nadesan
Lakshmi Pritha Nadesan

Posted on

Task 2 : Database

Create cinema table for storing movie information:

employee=# create table cinema(id int,movie_name varchar(20), actor varchar(20),year int,minutes int);
CREATE TABLE
Enter fullscreen mode Exit fullscreen mode

Insert movie details into movie table:

employee=# insert into cinema values(1,'Dharbar','Rajini',2021,121),(2,'Vikram','Kamal',2023,125),(3,'Mersal','Vijay',2020,123),(4,'Beast','Vijay',2019,134),(5,'Viswasam','Ajith',2021,117),(6,'Attakasam','Ajith',2006,119),(7,'Jai Bhim','Surya',2018,127),(8,'Kaithi','Karthi',2017,125),(9,'Ayothi','Sasikumar',2023,124),(10,'Deivathirumagan','Vikram',2017,121);
INSERT 0 10

employee=# select * from cinema;
 id |   movie_name    |   actor   | year | minutes 
----+-----------------+-----------+------+---------
  1 | Dharbar         | Rajini    | 2021 |     121
  2 | Vikram          | Kamal     | 2023 |     125
  3 | Mersal          | Vijay     | 2020 |     123
  4 | Beast           | Vijay     | 2019 |     134
  5 | Viswasam        | Ajith     | 2021 |     117
  6 | Attakasam       | Ajith     | 2006 |     119
  7 | Jai Bhim        | Surya     | 2018 |     127
  8 | Kaithi          | Karthi    | 2017 |     125
  9 | Ayothi          | Sasikumar | 2023 |     124
 10 | Deivathirumagan | Vikram    | 2017 |     121
(10 rows)
Enter fullscreen mode Exit fullscreen mode

1) List down 8th row values from the table:

employee=# select * from cinema limit 1  offset 7;
 id | movie_name | actor  | year | minutes 
----+------------+--------+------+---------
  8 | Kaithi     | Karthi | 2017 |     125
(1 row)
Enter fullscreen mode Exit fullscreen mode

2) List down all the movies released between 2021 and 2023:

employee=# select movie_name from cinema where year between 2021 and 2023;
 movie_name 
------------
 Dharbar
 Vikram
 Viswasam
 Ayothi
(4 rows)
Enter fullscreen mode Exit fullscreen mode

3) List down all the movies released not between 2021 and 2023:

employee=# select movie_name from cinema where year not between 2021 and 2023;
   movie_name    
-----------------
 Mersal
 Beast
 Attakasam
 Jai Bhim
 Kaithi
 Deivathirumagan
(6 rows)
Enter fullscreen mode Exit fullscreen mode

4) List down first 3 movies based on released year in descending order:

employee=# select movie_name from cinema order by year desc limit 3 ;
 movie_name 
------------
 Vikram
 Ayothi
 Dharbar
(3 rows)
Enter fullscreen mode Exit fullscreen mode

5) List down All movies by Vijay in the year 2020:

employee=# select movie_name from cinema where actor='vijay' or year=2020;
 movie_name 
------------
 Mersal
(1 row)
Enter fullscreen mode Exit fullscreen mode

6) List down all movies where we have ‘as’ in the movie name:

employee=# select movie_name from cinema where movie_name like '%as%'; 
 movie_name 
------------
 Beast
 Viswasam
 Attakasam
(3 rows)
Enter fullscreen mode Exit fullscreen mode

7) List down all actor names without duplicates:

employee=# select distinct actor from cinema;
   actor   
-----------
 Sasikumar
 Kamal
 Vijay
 Karthi
 Surya
 Ajith
 Rajini
 Vikram
(8 rows)

Enter fullscreen mode Exit fullscreen mode

8) List down Ajith movies in alphabetical order:

employee=# select movie_name from cinema where  actor='Ajith' order by movie_name;
 movie_name 
------------
 Attakasam
 Viswasam
(2 rows)
Enter fullscreen mode Exit fullscreen mode

9) List down movies where their names start with ‘A’ and actor name starts with ‘A’:

employee=# select movie_name from cinema where actor like 'A%' and movie_name like 'A%';
 movie_name 
------------
 Attakasam
(1 row)
Enter fullscreen mode Exit fullscreen mode

10) List down movies if the movie name is ‘Vikram’ or the actor name is ‘Vikram’:

employee=# select movie_name from cinema where actor='Vikram' or movie_name='Vikram';
   movie_name    
-----------------
 Vikram
 Deivathirumagan
(2 rows)

Enter fullscreen mode Exit fullscreen mode

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

If this post resonated with you, feel free to hit ❤️ or leave a quick comment to share your thoughts!

Okay