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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:04:05+00:00 2026-05-23T08:04:05+00:00

I am trying to implement a top-result search for a playlist. The tables are

  • 0

I am trying to implement a top-result search for a playlist. The tables are like so:

Playlist: id, title
Assignments: id, youtube_id, position
Videos: youtube_id, title

So joining them is simply: Playlist =(id)= Assignments =(youtube_id)= Videos

I want to find the first playlist on a title match (Titles are not unique) and match it to each of it’s videos, to bring back a list of videos in that playlist. I tried the following query:

SELECT * 
FROM ( 
SELECT id, title, position, youtube_id
FROM playlists p 
JOIN playlist_assignments pa 
USING(id) 
WHERE 1 and title = 'My Top Videos'
LIMIT 1
)d 
JOIN videos v 
USING (youtube_id)
ORDER BY position ASC

Unfortunately, the query will only return 1 row, the playlist matched with just the first video. How can I limit the subquery to just the top result, but still have a final result of a multiple row answer?

  • 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-23T08:04:05+00:00Added an answer on May 23, 2026 at 8:04 am

    The issue with your query is that the sub-query is doing a LIMIT 1, which means that though you retrieved a single playlist but then you also retrieved a single youtube_id. Then when did you ran a JOIN with videos on that single youtube_id, it gives you a single record.

    The fix might be to SELECT only from playlists table in the sub-query and move the JOIN for playlist_assignments outside together with the videos join. Something like:

    SELECT *
    FROM (
        SELECT id, title, position, youtube_id
        FROM playlists p 
        WHERE title = 'My Top Videos'
        LIMIT 1
    ) d 
    JOIN playlist_assignments pa USING (id)
    JOIN videos v 
    USING (youtube_id)
    ORDER BY position ASC;
    

    My suggested query is:

    SELECT `p`.`id` `playlist_id`, `p`.`title` `playlist_title`, `v`.`youtube_id` `youtube_id`, `v`.`title` `youtube_title`, `pa`.`position` 
    FROM `playlists` `p`
    INNER JOIN `playlist_assignments` `pa` ON `p`.`id` = `pa`.`id`
    INNER JOIN `videos` `v` ON `pa`.`youtube_id` = `v`.`youtube_id`
    WHERE `p`.`title` = 'My Top Videos'
    ORDER BY `pa`.`position`;
    

    Hope this helps. Let me know if it worked or if it didn’t.

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

Sidebar

Related Questions

I'm trying to implement search result highlighting for pdfs in a web app. I
I'm trying to implement the following code: verify.html: <input type=text id=vericode style=position:relative;top:-3px;width:70px;height:20px;border:1px solid #928b8b
Trying to implement a search similar to here .This searches properties based on city,locality,property
I'm trying to implement a iGoogle like dashboard interface using widgets that get their
I've been trying tom implement the following script which looks like a great date
I am trying to implement a simple Backbone app on top of RequireJS, but
I am trying to implement a search feature into my codeIgniter project. I have
I am trying to implement an action to scroll to the top of a
I am currently trying to write a simple shoot them up game with top
I am trying to implement a UIViewController hirarchy where the top most UIView Controller

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.