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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:27:43+00:00 2026-06-07T10:27:43+00:00

I have 2 tables that Im trying to select 4 results from ordered by

  • 0

I have 2 tables that Im trying to select 4 results from ordered by GalleryID DESC. The fields Im looking to return are GalleryID, GalleryTitle, GalleryDate from the Galleries table, and MediaThumb from the Media Table.

Now the catch is that the Media table has multiples of 10 of GalleryID’s. So, there could be 10 rows in the Media table with the same GalleryID. All I need is one MediaThumb to go along with the galleryid.

Im not sure how to formulate a query to return 4 distinct galleryid’s from the galleries table and a MediaThumb from the media table.

Essentially what im trying to do is return 4 unique photo galleries with a cover photo from the media table.

Any help would be appreciated. I provided a snapshot via query designer in sqlserver of my 2 tables.

enter image description here

  • 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-07T10:27:46+00:00Added an answer on June 7, 2026 at 10:27 am

    Something like this?

    SELECT TOP 4 
        g.GalleryID
        ,g.GalleryTitle
        ,g.GalleryDate
        ,MAX(m.MediaThumb) AS MaxMediaThumb
    FROM Galleries g
        INNER JOIN Media m
            ON g.GalleryID = m.GalleryID
    GROUP BY g.GalleryID, g.GalleryTitle, g.GalleryDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 3 tables that I'm trying to join and get distinct results.
I have several tables that I am selecting data from. I am trying to
I'm trying to make a select statement that joins results from three in-line table
I am having a problem sorting results from joining tables that have to be
I have two tables that I'm trying to create a relationship between so I
I have 3 tables that I am trying to combine into one with a
I have two tables in the system. I'm trying to make a VIEW that
I'm trying to SELECT from two tables and ORDER BY date (a column they
I'm trying to normalize a mysql database.... I currently have a table that contains
I have a data.frame and I'm trying to create a frequency table that shows

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.