sub queries
Posted by: jmmal2
Date: October 10, 2004 01:50AM
Date: October 10, 2004 01:50AM
hey all i was wondering if anyone was able to help me with my small problem.
mysql> describe film;
+-----------+----------------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------------------+------+-----+------------+-------+
| filmNo | smallint(4) unsigned | | PRI | 0 | |
| filmName | varchar(40) | | | | |
| dirId | smallint(4) unsigned | | | 0 | |
| dateAdded | date | | | 0000-00-00 | |
| yearMade | year(4) | YES | | NULL | |
+-----------+----------------------+------+-----+------------+-------+
5 rows in set (0.05 sec)
this is the film table
mysql> describe filmcopy;
+------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------------+------+-----+---------+-------+
| copyid | smallint(4) unsigned | | PRI | 0 | |
| filmid | smallint(4) unsigned | | PRI | 0 | |
| buyerid | smallint(4) unsigned | | | 0 | |
| mastercopy | enum('Y','N') | | | Y | |
| format | enum('Video','DVD') | | | Video | |
+------------+----------------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
this is the filmcopy table
mysql> describe buyer;
+------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------------+------+-----+---------+-------+
| buyerid | smallint(4) unsigned | | PRI | 0 | |
| buyerfname | char(10) | | | | |
| buyersname | char(10) | | | | |
| pcode | char(4) | | | | |
| discount | float | YES | | NULL | |
+------------+----------------------+------+-----+---------+-------+
5 rows in set (0.05 sec)
this is the buyer copy
****now i need to find the film's that have not sold any copies?***
***This is what i have found so far***
mysql> select distinct (f.filmno), f.filmname
-> from film f;
+--------+----------------------------+
| filmno | filmname |
+--------+----------------------------+
| 1 | 2001: A Space Odyssey |
| 2 | Casablanca |
| 3 | Fanny nad Alexander |
| 4 | The Cars That Ate Paris |
| 5 | Picnic At Hanging Rock |
| 6 | Mad Max |
| 7 | Mad Max2: The Road Warrior |
| 8 | Clockwork Orange |
+--------+----------------------------+
8 rows in set (0.00 sec)
this shows all films available.
mysql> select distinct c.filmid
-> from filmcopy c
-> where c.buyerid >0;
+--------+
| filmid |
+--------+
| 1 |
| 2 |
| 4 |
| 6 |
| 7 |
| 8 |
| 5 |
+--------+
7 rows in set (0.01 sec)
*******this shows that film no 3 has sold know copies.********
*****How do i create a subquery to display filmno 3 **** has sold no copies
if anyone can help that would be great
**here is some more stuff that might help
mysql> select * from filmcopy;
+--------+--------+---------+------------+--------+
| copyid | filmid | buyerid | mastercopy | format |
+--------+--------+---------+------------+--------+
| 1 | 1 | 0 | Y | Video |
| 1 | 2 | 0 | Y | Video |
| 1 | 3 | 0 | Y | Video |
| 1 | 4 | 0 | Y | Video |
| 1 | 5 | 0 | Y | Video |
| 1 | 6 | 0 | Y | DVD |
| 1 | 7 | 0 | Y | DVD |
| 1 | 8 | 0 | Y | DVD |
| 2 | 1 | 1 | N | Video |
| 2 | 2 | 3 | N | Video |
| 2 | 4 | 4 | N | Video |
| 2 | 5 | 0 | Y | DVD |
| 2 | 6 | 5 | N | DVD |
| 2 | 7 | 1 | N | DVD |
| 2 | 8 | 4 | N | DVD |
| 3 | 2 | 5 | N | Video |
| 3 | 4 | 5 | N | Video |
| 3 | 5 | 2 | N | DVD |
| 3 | 6 | 0 | Y | Video |
| 3 | 7 | 5 | N | DVD |
| 3 | 8 | 5 | N | DVD |
| 4 | 5 | 5 | N | DVD |
| 4 | 6 | 2 | N | Video |
| 5 | 5 | 1 | N | Video |
| 5 | 6 | 4 | N | DVD |
+--------+--------+---------+------------+--------+
25 rows in set (0.00 sec)
mysql> select * from film;
+--------+----------------------------+-------+------------+----------+
| filmNo | filmName | dirId | dateAdded | yearMade |
+--------+----------------------------+-------+------------+----------+
| 1 | 2001: A Space Odyssey | 1 | 1990-01-15 | 1968 |
| 2 | Casablanca | 2 | 1990-01-15 | 1942 |
| 3 | Fanny nad Alexander | 4 | 1990-01-15 | 1983 |
| 4 | The Cars That Ate Paris | 5 | 1992-04-22 | 1974 |
| 5 | Picnic At Hanging Rock | 5 | 1992-04-22 | 1975 |
| 6 | Mad Max | 3 | 1992-04-22 | 1979 |
| 7 | Mad Max2: The Road Warrior | 3 | 1992-04-22 | 1971 |
| 8 | Clockwork Orange | 1 | 2002-09-28 | 1971 |
+--------+----------------------------+-------+------------+----------+
8 rows in set (0.01 sec)
mysql> select * from buyer;
+---------+------------+------------+-------+----------+
| buyerid | buyerfname | buyersname | pcode | discount |
+---------+------------+------------+-------+----------+
| 1 | Christine | Slater | 3145 | 0 |
| 2 | George | Rice | 3142 | 2.5 |
| 3 | Cheryl | Gregory | 3146 | 2.5 |
| 4 | Ray | Gregory | 3146 | 5 |
| 5 | Andy | Campbell | 3147 | 5 |
+---------+------------+------------+-------+----------+
5 rows in set (0.00 sec)
mysql> describe film;
+-----------+----------------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------------------+------+-----+------------+-------+
| filmNo | smallint(4) unsigned | | PRI | 0 | |
| filmName | varchar(40) | | | | |
| dirId | smallint(4) unsigned | | | 0 | |
| dateAdded | date | | | 0000-00-00 | |
| yearMade | year(4) | YES | | NULL | |
+-----------+----------------------+------+-----+------------+-------+
5 rows in set (0.05 sec)
this is the film table
mysql> describe filmcopy;
+------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------------+------+-----+---------+-------+
| copyid | smallint(4) unsigned | | PRI | 0 | |
| filmid | smallint(4) unsigned | | PRI | 0 | |
| buyerid | smallint(4) unsigned | | | 0 | |
| mastercopy | enum('Y','N') | | | Y | |
| format | enum('Video','DVD') | | | Video | |
+------------+----------------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
this is the filmcopy table
mysql> describe buyer;
+------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------------------+------+-----+---------+-------+
| buyerid | smallint(4) unsigned | | PRI | 0 | |
| buyerfname | char(10) | | | | |
| buyersname | char(10) | | | | |
| pcode | char(4) | | | | |
| discount | float | YES | | NULL | |
+------------+----------------------+------+-----+---------+-------+
5 rows in set (0.05 sec)
this is the buyer copy
****now i need to find the film's that have not sold any copies?***
***This is what i have found so far***
mysql> select distinct (f.filmno), f.filmname
-> from film f;
+--------+----------------------------+
| filmno | filmname |
+--------+----------------------------+
| 1 | 2001: A Space Odyssey |
| 2 | Casablanca |
| 3 | Fanny nad Alexander |
| 4 | The Cars That Ate Paris |
| 5 | Picnic At Hanging Rock |
| 6 | Mad Max |
| 7 | Mad Max2: The Road Warrior |
| 8 | Clockwork Orange |
+--------+----------------------------+
8 rows in set (0.00 sec)
this shows all films available.
mysql> select distinct c.filmid
-> from filmcopy c
-> where c.buyerid >0;
+--------+
| filmid |
+--------+
| 1 |
| 2 |
| 4 |
| 6 |
| 7 |
| 8 |
| 5 |
+--------+
7 rows in set (0.01 sec)
*******this shows that film no 3 has sold know copies.********
*****How do i create a subquery to display filmno 3 **** has sold no copies
if anyone can help that would be great
**here is some more stuff that might help
mysql> select * from filmcopy;
+--------+--------+---------+------------+--------+
| copyid | filmid | buyerid | mastercopy | format |
+--------+--------+---------+------------+--------+
| 1 | 1 | 0 | Y | Video |
| 1 | 2 | 0 | Y | Video |
| 1 | 3 | 0 | Y | Video |
| 1 | 4 | 0 | Y | Video |
| 1 | 5 | 0 | Y | Video |
| 1 | 6 | 0 | Y | DVD |
| 1 | 7 | 0 | Y | DVD |
| 1 | 8 | 0 | Y | DVD |
| 2 | 1 | 1 | N | Video |
| 2 | 2 | 3 | N | Video |
| 2 | 4 | 4 | N | Video |
| 2 | 5 | 0 | Y | DVD |
| 2 | 6 | 5 | N | DVD |
| 2 | 7 | 1 | N | DVD |
| 2 | 8 | 4 | N | DVD |
| 3 | 2 | 5 | N | Video |
| 3 | 4 | 5 | N | Video |
| 3 | 5 | 2 | N | DVD |
| 3 | 6 | 0 | Y | Video |
| 3 | 7 | 5 | N | DVD |
| 3 | 8 | 5 | N | DVD |
| 4 | 5 | 5 | N | DVD |
| 4 | 6 | 2 | N | Video |
| 5 | 5 | 1 | N | Video |
| 5 | 6 | 4 | N | DVD |
+--------+--------+---------+------------+--------+
25 rows in set (0.00 sec)
mysql> select * from film;
+--------+----------------------------+-------+------------+----------+
| filmNo | filmName | dirId | dateAdded | yearMade |
+--------+----------------------------+-------+------------+----------+
| 1 | 2001: A Space Odyssey | 1 | 1990-01-15 | 1968 |
| 2 | Casablanca | 2 | 1990-01-15 | 1942 |
| 3 | Fanny nad Alexander | 4 | 1990-01-15 | 1983 |
| 4 | The Cars That Ate Paris | 5 | 1992-04-22 | 1974 |
| 5 | Picnic At Hanging Rock | 5 | 1992-04-22 | 1975 |
| 6 | Mad Max | 3 | 1992-04-22 | 1979 |
| 7 | Mad Max2: The Road Warrior | 3 | 1992-04-22 | 1971 |
| 8 | Clockwork Orange | 1 | 2002-09-28 | 1971 |
+--------+----------------------------+-------+------------+----------+
8 rows in set (0.01 sec)
mysql> select * from buyer;
+---------+------------+------------+-------+----------+
| buyerid | buyerfname | buyersname | pcode | discount |
+---------+------------+------------+-------+----------+
| 1 | Christine | Slater | 3145 | 0 |
| 2 | George | Rice | 3142 | 2.5 |
| 3 | Cheryl | Gregory | 3146 | 2.5 |
| 4 | Ray | Gregory | 3146 | 5 |
| 5 | Andy | Campbell | 3147 | 5 |
+---------+------------+------------+-------+----------+
5 rows in set (0.00 sec)
Subject
Written By
Posted
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.