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

  • SEARCH
  • Home
  • 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 7430433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:08:24+00:00 2026-05-29T09:08:24+00:00

I am currently working on a MYSQL project which has a few fairly standard

  • 0

I am currently working on a MYSQL project which has a few fairly standard many to many relationship.

I’ve shown a greatly simplified relationship table to aid my example.

table: book_authors
ID    BOOKS   AUTHORS
1     1       4
2     1       5
3     4       4
4     4       5
5     2       6
6     2       1
7     2       5
8     3       6
9     3       5
10    3       1
12    5       2
13    6       2
14    7       5

What I’m looking to achieve is to be able to select all books which have specified authors, and only get the books which match all of the supplied authors. The number of authors requested each time is also variable.

So if i’m looking for all books written by author 4 and author 5, I’ll get result of books 1 and 4 only. If im looking for books written by author 5 only, i’ll get book 7 only.

  • 1 1 Answer
  • 0 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-29T09:08:25+00:00Added an answer on May 29, 2026 at 9:08 am

    I don’t think there’s a very smooth way to do this, but if performance isn’t a big concern, you can exploit MySQL’s GROUP_CONCAT function, and write this:

    SELECT books
      FROM book_authors
     WHERE books IN
            ( SELECT books
                FROM book_authors
               WHERE authors = 4
            )
     GROUP
        BY books
    HAVING GROUP_CONCAT(authors ORDER BY authors) = '4,5'
    ;
    

    (The WHERE clause isn’t even needed for correct results, but it makes the query less gratuitously expensive.)

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

Sidebar

Related Questions

I am currently working on a project which has to use WebSockets as a
I am currently working on a C# (.NET) project which connects to a MySQL
I'm currently working on a project that makes use of Seam/Hibernate (JPA) on MySQL.
I am working on a project which uses Java,MySql,Struts2 MVC and Hibernate. I tried
I am currently working on a php/javascript project which retrieves information from a database
So I'm working on a side project using MySQL/MyBatis3/Tomcat. I'm currently working on turning
I am currently working on a C# project that will export MySQL Data. The
I'm currently working on a Java EE project which uses JPA. I'm connecting to
I am currently working on a project in which I have to keep track
I'm currently using Spring+Hibernate+MySQL for a project I'm working on. I realized that a

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.