Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1002737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:52:18+00:00 2026-05-16T07:52:18+00:00

i want help how to solve this sql problem. suppose i have 3 tables

  • 0

i want help how to solve this sql problem.
suppose i have 3 tables

Movie

  • ID
  • Name

Genre

  • ID
  • Name

Movie_Genre (this one is the link for many to many)

  • FK_MovieID
  • FK_GenreID

i want to select all the movies that are of genre 1 and genre 3
how is this possible?
i can only select the movies of 1 genre but not the movies that are of 2 genres using

    SELECT Movie.ID, Movie.Name 
      FROM Movies
INNER JOIN Movie_Genre ON Movie_Genre.FK_MovieID=Movie.ID
                      AND Movie_Genre.FK_GenreID = 1
  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:52:18+00:00Added an answer on May 16, 2026 at 7:52 am

    Use:

      SELECT m.id, 
             m.name
        FROM MOVIE m
        JOIN MOVIE_GENRE mg ON mg.fk_movieid = m.id
                           AND mg.fk_genreid IN (1, 3)
    GROUP BY m.id, m.name
      HAVING COUNT(DISTINCT mg.fk_genreid) = 2
    

    The last line is key to getting rows from both genre’s – the DISTINCT means duplicate associations (IE: two instances of genre 1) will be ignored because they are false positives. But the count must equal the number of genres you are looking for.

    But COUNT(DISINCT isn’t supported by all databases. You should mention what you are using – if not by tag, then in the question… If the primary key for the MOVIE_GENRE table is both fk_movieid and fk_genreid, then it’s not an issue. Next best thing would be that both the columns are in a unique constraint/index…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem is giving me a real headache. I have two tables in my
Please help me solve this: I have got this: var text='<li id=job1>Job 1</li>'+ '<li
Can you help me solve this problem? I've not managed to find any documentation
I want help on this script I am making... I want my website to
I have another problem with PyQT, this time I have an example that will
Dear LINQ or linq2sql experts, can you help me to solve this case? I
I have a .net application using sql server 2005 database. This is a very
I have a following problem. I have a ListView which returns data from SQL
im very new to this and have a very basic knowledge php and SQL
I need a help on sql database side. And i have table 1 :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.