Results 1 to 3 of 3
  1. #1
    lostlad is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    4

    Question Query within a query / Query based on results of another query

    Good evening all.



    Firstly thank you for any help that you may be able to provide. (This is a continuation from https://www.accessforums.net/databas...tbl-51469.html)

    I have a task to create a Movie database similar in functionality to IMDB whereby I can search for stars featured in a particular movie, also a search for all movies featuring a particular star.

    Click image for larger version. 

Name:	relationship.png 
Views:	8 
Size:	103.0 KB 
ID:	20276

    As you can see by the relationship diagram it is simple. Movies and actors are linked by a junction/link box to break up the many-many connection.

    I am trying to create a query that will identify all films that feature two particular actors. For example, what films have featured both Will Smith and Bruce Willis (fictional data).

    I assume i need to run two queries to gather the data and then somehow perform a third query to match the films. Here is my query data for the actors to see what movies they star in. If anybody has any advice or preferably a solution it would be greatly appreciated.

    Here are my queries:
    SELECT
    Actors_TBL.actor_ID AS Actors_TBL_actor_ID, Actors_TBL.actor_gender, Actors_TBL.actor_First_Name, Actors_TBL.actor_Last_Name, Actors_TBL.Nationality_LKP, Movies_TBL.movie_ID AS Movies_TBL_movie_ID, Movies_TBL.movie_title, Movies_TBL.movie_description, Movies_TBL.movie_genre, Movies_TBL.date_release, Movies_Actors_LINK.movie_ID AS Movies_Actors_LINK_movie_ID, Movies_Actors_LINK.actor_ID AS Movies_Actors_LINK_actor_ID


    FROM Movies_TBL INNER JOIN (Actors_TBL INNER JOIN Movies_Actors_LINK ON Actors_TBL.[actor_ID] = Movies_Actors_LINK.[actor_ID]) ON Movies_TBL.[movie_ID] = Movies_Actors_LINK.[movie_ID]
    WHERE (((Actors_TBL.actor_First_Name)="will") AND ((Actors_TBL.actor_Last_Name)="smith"));
    and


    SELECT
    Actors_TBL.actor_ID AS Actors_TBL_actor_ID, Actors_TBL.actor_gender, Actors_TBL.actor_First_Name, Actors_TBL.actor_Last_Name, Actors_TBL.Nationality_LKP, Movies_TBL.movie_ID AS Movies_TBL_movie_ID, Movies_TBL.movie_title, Movies_TBL.movie_description, Movies_TBL.movie_genre, Movies_TBL.date_release, Movies_Actors_LINK.movie_ID AS Movies_Actors_LINK_movie_ID, Movies_Actors_LINK.actor_ID AS Movies_Actors_LINK_actor_ID

    FROM Movies_TBL INNER JOIN (Actors_TBL INNER JOIN Movies_Actors_LINK ON Actors_TBL.[actor_ID] = Movies_Actors_LINK.[actor_ID]) ON Movies_TBL.[movie_ID] = Movies_Actors_LINK.[movie_ID]
    WHERE (((Actors_TBL.actor_First_Name)="bruce") AND ((Actors_TBL.actor_Last_Name)="willis"));
    I am trying to achieve a query that given two names (query 1 and 2) it will list all films which star both actors.

    Thank you very much

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What if you wanted 3 or 4 or more actors?
    Multiple criteria on same field best done with IN operator. Review http://allenbrowne.com/ser-50.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    lostlad is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    4
    Thankyou very much June7.

    My requirement criteria is only to find a movie featuring a person and a specific other however you are right. This question could be extended to match a larger cast, 3,4 actors etc.

    I will read your recommended link now and let you know how i get on.

    Thank you very much as always

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query results based on checked record.
    By jtm013 in forum Queries
    Replies: 3
    Last Post: 08-14-2014, 10:43 AM
  2. Replies: 2
    Last Post: 02-02-2014, 07:19 PM
  3. Replies: 7
    Last Post: 07-11-2013, 10:45 AM
  4. Create Message Box based on query results
    By stanley721 in forum Queries
    Replies: 7
    Last Post: 02-14-2013, 10:04 AM
  5. Open form based on query results
    By RobbertH in forum Queries
    Replies: 1
    Last Post: 02-10-2010, 08:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums