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

The Archive Base Latest Questions

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

Could I get some help creating this query please? Users book product video slots

  • 0

Could I get some help creating this query please?

Users book product video slots to advertise ONE product video. The booking table captures these bookings. Booking spots are allocated to a user not to a product or video.
The #1-ranked video for the user’s #1-ranked product will be the one that is advertised.

Bookings table

id   user_id   position  
---- -----     --------       
1     100        1             
2     150        2               

Users table
Users can have 1-n bookings

id     name
----   ----
100    John Smith
150    Herby Brown

Products table
A user can have 1-n products

id    name      user_id   rank   
---   ----      -------   ----     
1     bike        100        1            
2     stereo      100        2 
3     computer    100        3
4     notebook    150        1
5     scooter     150        2

Videos table
A product can have 1-n videos

id    name            product_id      user_id   rank   
---   ----            -----------     -------   ----   
1     bike video1        1               100      1            
2     bike video2        1               100      2 
3     computer video     3               100      3
4     notebook video     4               150      1
5     scooter video      5               150      2

So, the query reads, in words:
For each booking record, get the #1 ranked video for the #1-ranked product for the booked user. Order the results by booking position.

  • 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-18T09:08:58+00:00Added an answer on May 18, 2026 at 9:08 am
    SELECT v.id, 
           v.name, 
           v.rank, 
           v.user_id, 
           u.name AS uname 
    FROM   videos v 
           JOIN users u 
             ON u.id = v.user_id 
           JOIN bookings b 
             ON u.id = b.user_id 
    WHERE  v.product_id = (SELECT id 
                           FROM   products 
                           WHERE  user_id = b.user_id 
                           ORDER  BY rank ASC 
                           LIMIT  1) 
    ORDER  BY b.position ASC, v.rank ASC
    

    some simplified query:

    SELECT v.id, 
           v.name, 
           v.user_id, 
           u.name AS uname, 
           p.name AS pname 
    FROM   videos v 
           JOIN users u 
             ON u.id = v.user_id 
           JOIN bookings b 
             ON u.id = b.user_id 
           JOIN products p 
             ON p.id = v.product_id 
    WHERE  v.product_id = (SELECT id 
                           FROM   products 
                           WHERE  user_id = b.user_id 
                                  AND rank = 1) 
           AND v.rank = 1 
    ORDER  BY b.position ASC 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just could not get this one and googling did not help much either.. First
Here is some code I could not get to format properly in markdown, this
This is the one thing I could never get to work. My problem is
I was wondering if there was somewhere I could get some starter kit /
Apologies for the long post, but I wonder if I could get some more
Could I get some confirmations from the community that I'm not going mad, and
Could someone supply some code that would get the xpath of a System.Xml.XmlNode instance?
I need some help with creating a regex for my php script. Basically, I
Is there any way that I could get the source of a website (as
We get the following error; The request was aborted: Could not create SSL/TLS secure

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.