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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:06:19+00:00 2026-05-19T09:06:19+00:00

I have a major problem getting this to work properly. Here is the deal.

  • 0

I have a major problem getting this to work properly. Here is the deal.

I have 4 tables – timeline, connections, images, votes

Timeline table:

time_id
time_title

etc.

The timeline table connects with the images table via the connections table

Connections table:

time_id
image_id

So the connections hold information about the id of the “post” the timeline and about image id

Images table:

image_id
image_url
image_type

Images table contains images that could be used in the same timeline(post), so by this i can see the connection by looking at the connection table.

I also have a votes table that holds information about votes for the specific timeline post

Votes table:

vote_id
time_id

the votes table contains many rows of each time_id and the idea is to count the number of times to se wich is the most popular

So heres the question:
I need to get the 5 most voted time_titles and show them with the first image for each time_title(post) so that it look like this for example

  • Image 1 that corresponds to Title 1 – that is the highest voted
  • Image 2 that corresponds to Title 2 – that is the second highest voted

etc.

Each timeline row (post) can hold many images and i only want to show the first of each post.

Hope you understand my problem!

Thanks a lot!

  • 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-19T09:06:20+00:00Added an answer on May 19, 2026 at 9:06 am

    The query will be

    SELECT
     count(v.vote_id) as vote_times
     t.time_title,
     ( 
      SELECT
       image_url
      FROM
       images 
      WHERE
       image_id = (
           SELECT
            image_id
           FROM
            connections as c
           WHERE
            c.time_id = t.time_id
           LIMIT 1
          )
      LIMIT 1
     ) as image_url
    FROM
     votes as v
      LEFT JOIN
       time as t 
        on 
         t.time_id = v.time_id
    GROUP BY
     v.time_id
    ORDER BY
     vote_times desc
    LIMIT 5;
    

    This will work, but might not be the most optimized one.

    — EDIT
    to get image_type also try

    SELECT
        count(v.vote_id) as vote_times
        t.time_title,
     i.image_url,
     i.image_type
    
    FROM
        votes as v
            LEFT JOIN
                time as t 
                    on 
                        t.time_id = v.time_id
      LEFT JOIN
       images as i
        on
         i.image_id = (
             SELECT
              image_id
             FROM
              connections as c
             WHERE
              c.time_id = t.time_id
             LIMIT 1
            )
    GROUP BY
        v.time_id
    ORDER BY
        vote_times desc, image_type desc
    LIMIT 5;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.