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 8389469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:44:09+00:00 2026-06-09T18:44:09+00:00

I want a mysql query for following scenario I have following database structure 1]

  • 0

I want a mysql query for following scenario
I have following database structure

1] table 'albums'  Columns  'id', 'name'
2] table 'tracks'  Columns  'id', 'title', 'album_id'   (album has many tracks)
3] table 'assets'  Columns  'id', 'track_id'   (track has many assets)

I want to find out all the albums such that, all the tracks of that album must have at least 2 assets.

For following test data
albums

'id'    'name'
  1      Album 1
  2      Album 2

tracks

  'id'    'title'        'album_id'
   1      Track 1       1
   2      Track 2       1
   3      Track 3       2
   4      Track 4       2

assets

'id'  'track_id'
 1      1
 2      1
 3      2
 4      2
 5      3
 6      3
 7      4

So my query o/p should be

'id'    'name'
  1      Album 1

As Album 1 has two tracks Track 1 and Track 2 and both of these tracks have 2 assets whereas Track 4 of Album 2 have only 1 asset

  • 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-06-09T18:44:10+00:00Added an answer on June 9, 2026 at 6:44 pm

    Try:

    SELECT    a.id,
              a.name
    FROM      albums a
    JOIN      tracks b ON a.id = b.album_id
    LEFT JOIN (
              SELECT   track_id
              FROM     assets
              GROUP BY track_id
              HAVING   COUNT(*) >= 2
              ) c ON b.id = c.track_id
    GROUP BY  a.id, 
              a.name
    HAVING    COUNT(*) = COUNT(c.track_id)
    

    SQLFiddle Demo

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

Sidebar

Related Questions

I want to query a MySQL database. I have the following. $name keeps changing
If I have three columns in my MySQL table people , say id, name,
I have the following MySQL query, which produces the result I want: SELECT `l`.`status`,
I have the following MySQL query: SELECT title, description FROM some_table WHERE MATCH (title,description)
I have a mysql query that is trying to combine the following tables: TABLE:
I have mysql database with following table... | id | amount | tax |
Basically I have a mysql query something like the following: mysql_query(SELECT n.title, v.value FROM
I want to accomplish this (mysql) query: UPDATE table SET field = field +
I have a question about my mysql query. I want to count the number
Hi i'm struggling to write a particular MySQL Join Query. I have a table

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.