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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:07:28+00:00 2026-06-12T18:07:28+00:00

Well, I have three different tables (check below). I wanted to make that I

  • 0

Well, I have three different tables (check below). I wanted to make that I can see, which is the latest image (req_image_1, etc) saved for each category, which is not parent (cat_parent = 0)

One table, which holds general information about requests

+----+--------------------------+------------+
| id | req_name                 | req_parent |
+----+--------------------------+------------+
|  3 | Send pack                |         19 |
|  4 | Go Visit                 |         18 |
|  5 | Stop by                  |         19 |
|  6 | Deliver cookies          |         34 |
+----+--------------------------+------------+

Second table, which holds meta information about requests

+----------+------------+------------+----------------------------+
| umeta_id | request_id | meta_key   | meta_value                 |
+----------+------------+------------+----------------------------+
|       1  |          3 | req_city   | London                     |
|       2  |          3 | req_street | 11 Baker street            |
|       3  |          3 | req_img_1  | a1c8f69edb37bf6c6.jpg      |
|       4  |          4 | req_city   | Manchester                 |
|       5  |          4 | req_street | 71 Main street             |
|       6  |          4 | req_img_2  | a71f4160d7f7f7555.jpg      |
|       7  |          5 | req_city   | Sheffield                  |
|       8  |          5 | req_street | 240 Duke street            |
|       9  |          6 | req_city   | Manchester                 |
|       10 |          6 | req_street | 13 Chapel street           |
|       11 |          6 | req_img_1  | 854b9faaa53d8fe02.jpg      |
+----------+------------+------------+----------------------------+

Third table, which holds information about categories

+----+------------------------+------------+
| ID | cat_name               | cat_parent |
+----+------------------------+------------+
|  1 | Category_01            |          0 |
|  6 | Category_02            |          0 |
| 18 | Category_01_01         |          1 |
| 19 | Category_01_02         |          1 |
| 34 | Category_02_01         |          6 |
+----+------------------------+------------+

So far I managed, that I could get all images for each category with this query:

SELECT cat.cat_parent AS category, req.ID, meta.meta_value AS image
FROM d_requests req
LEFT JOIN d_requests_meta meta ON ( req.ID = meta.request_id ) 
LEFT JOIN d_categories cat ON ( req.req_parent = cat.ID ) 
WHERE meta.meta_key LIKE 'req_img_%'

I got this result:

+------------+----+-----------------------+
| category   | ID | image                 |
+------------+----+-----------------------+
|          1 |  3 | a1c8f69edb37bf6c6.jpg |
|          1 |  4 | a71f4160d7f7f7555.jpg |
|          6 |  6 | 854b9faaa53d8fe02.jpg |
+------------+----+-----------------------+

But I wanted to make enhancement, so I would get only result, where each category has only one image against, for example category 1, has image a71f4160d7f7f7555.jpg and category 6 has image 854b9faaa53d8fe02.jpg

I bet, that I miss some basic knowledge, and simple enhancement with subquery and selecting MAX would work as a charm.

Thanks!

  • 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-12T18:07:30+00:00Added an answer on June 12, 2026 at 6:07 pm
    SELECT category, ID, image
    FROM (  SELECT cat.cat_parent AS category, req.ID, meta.meta_value AS image
            FROM d_requests AS req
            LEFT JOIN d_requests_meta AS meta
            ON req.ID = meta.request_id
            LEFT JOIN d_categories AS cat
            ON req.req_parent = cat.ID
            WHERE meta.meta_key LIKE 'req_img_%'
            ORDER BY req.ID DESC) AS h
    GROUP BY category
    

    I edited Clodoaldo’s answer with the use of the inofficial MySQL assumption that GROUP BY will return the 1st row based on ORDER BY in subquery.

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

Sidebar

Related Questions

Well, I have a number of different content types that I want to make
Here's my problem: I have three tables that represent a many to many relationship
Well i have a div tag that i show as a modal dialog this
well I have that problem, im using a lightbox srcipt and im opening an
I have the following sql which returns Projects and related Contractors as well as
So, I've got some history tables that have a begin date and an end
Well, I have been working with large amount of network data. In which I
I have an iPhone app that has several different view controllers. A login screen
I have a complex situation, where I need to map three different classes with
Each product in my database can have at least three and sometimes four or

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.