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

The Archive Base Latest Questions

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

I am sure there is a way to do this, but being that I

  • 0

I am sure there is a way to do this, but being that I am still new to MySQL and PHP, I can’t figure this out.

I have a table where the first column (base_folder) represents a folder, there are multiple images in that folder (sub_folder). The last field (layer) represents the image order. What I need to get is the max number from the layer column where the base_folder, the sub_folder, image_, image_type and view are identical.

Does anyone have any idea how to do to that?

Here is the table:

+-------------------------------------------------------------------------+
|                                BASE_IMAGE                               |
+-----+-------------+------------+-------------+----------+-------+-------+
| id  | base_folder | sub_folder | image       |image_type|  view | layer |          
+-----+-------------+------------+-------------+----------+-------+-------+
|  1  | CUP0001     |   F        | B_FF_0.png  |   B      |   FF  |   0   |
+-----+-------------+------------+-------------+----------+-------+-------+
|  2  | CUP0001     |   F        | B_FF_0.png  |   B      |   FF  |   1   |
+-----+-------------+------------+-------------+----------+-------+-------+
|  3  | CUP0001     |   F        | B_FF_0.png  |   B      |   FF  |   2   |
+-----+-------------+------------+-------------+----------+-------+-------+
|  4  | CUP0001     |   F        | B_FF_0.png  |   M      |   FF  |   0   |
+-----+-------------+------------+-------------+----------+-------+-------+

What I would like to get is “2” for where the base_folder[‘CUP0001’], sub_folder[‘F’], image[‘B_FF_0.png’], image_type[‘B’], view[‘FF’], layer[‘2’]

  • 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-23T17:00:00+00:00Added an answer on May 23, 2026 at 5:00 pm

    The direct answer to the original question is:

    SELECT MAX(layer)
      FROM Base_Image
     WHERE Base_Folder = 'CUP0001'
       AND Sub_Folder  = 'F'
       AND Image       = 'B_FF_0.png'
       AND Image_Type  = 'B'
       AND View        = 'FF';
    

    If you need the maximum layer for each combination of the five fields, then you need a GROUP BY clause and you need to select the identifying columns too:

    SELECT Base_Folder, Sub_Folder, Image, Image_Type, View, MAX(layer) AS MaxLayer
      FROM Base_Image
     GROUP BY Base_Folder, Sub_Folder, Image, Image_Type, View;
    

    (Withdrawn:
    It looks suspiciously as if your table is not properly normalized; there is at least room to suppose that the combination of Base_Folder, Sub_Folder, Image controls the values of Image_Type and View. However, the code shown will work whether this comment is accurate or not.
    )


    If the long combinations are not good, […] do you have a suggestion on a better approach?

    It depends on the volume of data, and how you’re going to be managing the data. It also depends on which parts of the data are independent. I would be tempted to split the table into two, though an extreme view might go as far as five tables:

    • ImageFile columns (ID, Base_Folder, Sub_Folder, Image) with primary key ID and alternate key (unique constraint) on (Base_Folder, Sub_Folder, Image).
    • ImageDetails (ID, ImageFileID, Image_Type, View, Layer, with primary key ID, alternate key (ImageFileID, Image_Type, View, Layer), and foreign key ImageFileID referencing ImageFile.ID.

    An alternative design for ImageDetails avoids the ID column and uses the alternate key as the primary key. It depends, in part, on whether anything else is going to reference the rows in this table.

    However, it all depends on what you’re going to do and how the data is really organized (what the functional dependencies are in the table you show). The extreme view would use: one table for the base folders; then there’d be a sub-folder table with a base folder ID and the sub-folder name an its own ID field, and then there’d be an image file table with its own ID, a sub-folder ID, and the image name; then there’d be an image type table for each image type of each image file (with its own ID plus an FK); and so on. This is harder to insert rows into; and every select operation that needs to filter on, say, base folder and image type needs to join a lot of tables. That needn’t be slow, but it complicates the SQL.

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

Sidebar

Related Questions

I am sure there is no easy way to do this but I have
I'm pretty sure there is no way, but i'm putting this out there for
I'm sure there's a clean way to do this, but I'm probably not using
I am sure there must be a relatively straightforward way to do this, but
I'm sure this works in VS2010 but is there any way to get snippets
I'm not sure if this is even possible, but is there a way to
I'm pretty sure there is an easier way to do this that I'm missing
I'm sure there's some way to do this with the \defgroup, \addgroup and \@{
I'm not sure if this is possible, is there a way to get the
Hi I'm sure there is some way of doing what I want, but maybe

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.