SQL Lab-6
SQL Lab-6
+--------------------+
| Database |
+--------------------+
| information_schema |
| lab1 |
| lab10 |
| lab2 |
| lab3 |
| lab8 |
| lab9 |
| mysql |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
11 rows in set (0.053 sec)
Database changed
MariaDB [lab6]> source C:\Users\aryan\Downloads\\rating.sql;
ERROR: Unknown command '\U'.
ERROR: Unknown command '\a'.
ERROR: Unknown command '\D'.
ERROR: Unknown command '\\'.
Query OK, 0 rows affected, 1 warning (0.048 sec)
C:\Users\aryan>mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.24-MariaDB mariadb.org binary distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [lab6]> select mID from Rating where stars in(3, 5);
+------+
| mID |
+------+
| 101 |
| 103 |
| 107 |
| 106 |
| 107 |
| 104 |
+------+
6 rows in set (0.001 sec)
MariaDB [lab6]> select rID, mID from Rating where ratingDate is not null;
+------+------+
| rID | mID |
+------+------+
| 201 | 101 |
| 201 | 101 |
| 203 | 103 |
| 203 | 108 |
| 203 | 108 |
| 204 | 101 |
| 205 | 103 |
| 205 | 104 |
| 206 | 107 |
| 206 | 106 |
| 207 | 107 |
| 208 | 104 |
+------+------+
12 rows in set (0.001 sec)
MariaDB [lab6]> select title from Movie, Rating where (Movie.mID=Rating.mID) and
(rID=203);
+-------------------------+
| title |
+-------------------------+
| The Sound of Music |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
+-------------------------+
3 rows in set (0.001 sec)
MariaDB [lab6]> select * from Movie, Rating r1, Rating r2 where ((Movie.mID=r1.mID)
and (Movie.mID=r2.mID) and r1.ID=205 and r2.ID=203);
ERROR 1054 (42S22): Unknown column 'r1.ID' in 'where clause'
MariaDB [lab6]> select * from Movie, Rating r1, Rating r2 where ((Movie.mID=r1.mID)
and (Movie.mID=r2.mID) and r1.rID=205 and r2.rID=203);
+------+-------------------------+------+------------------+------+------+-------
+------------+------+------+-------+------------+
| mID | title | year | director | rID | mID | stars |
ratingDate | rID | mID | stars | ratingDate |
+------+-------------------------+------+------------------+------+------+-------
+------------+------+------+-------+------------+
| 103 | The Sound of Music | 1965 | Robert Wise | 205 | 103 | 3 |
2011-01-27 | 203 | 103 | 2 | 2011-01-20 |
| 108 | Raiders of the Lost Ark | 1981 | Steven Spielberg | 205 | 108 | 4 |
NULL | 203 | 108 | 4 | 2011-01-12 |
| 108 | Raiders of the Lost Ark | 1981 | Steven Spielberg | 205 | 108 | 4 |
NULL | 203 | 108 | 2 | 2011-01-30 |
+------+-------------------------+------+------------------+------+------+-------
+------------+------+------+-------+------------+
3 rows in set (0.001 sec)
MariaDB [lab6]> select title from Movie, Rating r1, Rating r2, Reviewer r3,
Reviewer r4 where (r3.name='Sarah Martinez' and r4.name='Mike Anderson' and
r3.rID=r1.rID and r4.rID=r2.rID and r1.mID=Movie.mID and r2.mID=Movie.mID);
+--------------------+
| title |
+--------------------+
| Gone with the Wind |
| Gone with the Wind |
+--------------------+
2 rows in set (0.004 sec)
MariaDB [lab6]> select r1.stars from Rating r1, Rating r2 where(r1.rID!=r2.rID and
r1.mID=r2.mID);
+-------+
| stars |
+-------+
| 3 |
| 3 |
| 5 |
| 3 |
| 4 |
| 4 |
| 2 |
| 4 |
| 2 |
| 4 |
| 2 |
| 5 |
| 4 |
| 3 |
| 2 |
| 3 |
+-------+
16 rows in set (0.001 sec)
MariaDB [lab6]> select r1.stars r1.mID from Rating r1, Rating r2 where(r1.rID!
=r2.rID and r1.mID=r2.mID);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near '.mID
from Rating r1, Rating r2 where(r1.rID!=r2.rID and r1.mID=r2.mID)' at line 1
MariaDB [lab6]> select r1.stars, r1.mID from Rating r1, Rating r2 where(r1.rID!
=r2.rID and r1.mID=r2.mID);
+-------+------+
| stars | mID |
+-------+------+
| 3 | 101 |
| 3 | 101 |
| 5 | 106 |
| 3 | 103 |
| 4 | 108 |
| 4 | 108 |
| 2 | 101 |
| 4 | 101 |
| 2 | 103 |
| 4 | 108 |
| 2 | 108 |
| 5 | 107 |
| 4 | 106 |
| 3 | 107 |
| 2 | 104 |
| 3 | 104 |
+-------+------+
16 rows in set (0.001 sec)
MariaDB [lab6]> select title from Movie, Rating where (Movie.mID=Rating.mID and
Rating.stars is null);
Empty set (0.001 sec)
MariaDB [lab6]> select title from Movie, Rating where Rating.mID is not in(select
mID from Movie);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'in(select mID from Movie)' at line 1
MariaDB [lab6]> select title from Movie, Rating where Rating.mID in(select mID from
Movie);
+-------------------------+
| title |
+-------------------------+
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Gone with the Wind |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| The Sound of Music |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| E.T. |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Snow White |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Avatar |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Raiders of the Lost Ark |
| Gone with the Wind |
| Star Wars |
| The Sound of Music |
| E.T. |
| Titanic |
| Snow White |
| Avatar |
| Raiders of the Lost Ark |
+-------------------------+
112 rows in set (0.003 sec)
MariaDB [lab6]> select title from Movie, Rating where Rating.mID not in(select mID
from Movie);
Empty set (0.002 sec)
MariaDB [lab6]> select title from Movie, Rating where Movie.mID not in(select mID
from Rating);
+-----------+
| title |
+-----------+
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Star Wars |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
| Titanic |
+-----------+
28 rows in set (0.001 sec)