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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:04:57+00:00 2026-05-27T17:04:57+00:00

My MySQL db has a table (cfg) with 4 fields: id, name, data, and

  • 0

My MySQL db has a table (cfg) with 4 fields: id, name, data, and location
This one table is to service several subdomains (location). I need to get a list of the newest rows for each name for a given subdomain (location).

Example data

id   name   data   location
---------------------------
1    color  red    dc
2    color  blue   dc
3    size   large  sj
4    color  green  sj
5    size   small  dc

The following query works fine, but it seems too complicated and slow. Does anyone have a suggestion?

SELECT c1.name, c1.data
FROM (SELECT * FROM cfg WHERE location = "dc") as c1
LEFT JOIN (SELECT * FROM cfg WHERE location = "dc") as c2 ON ( c1.name = c2.name
AND c1.id < c2.id )
WHERE c2.id IS NULL

It would return

name     data
--------------
color    blue
size     small
  • 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-27T17:04:58+00:00Added an answer on May 27, 2026 at 5:04 pm

    Use a subquery with GROUP BY that computes the max. id per name:

    SELECT cfg.*
    FROM   cfg
    JOIN  (
        SELECT max(id) AS max_id
        FROM   cfg c0
        WHERE  location = 'dc'
        GROUP  BY name
        ) n ON n.max_id = cfg.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: A Table in MySQL that has a few normal fields and one text
I have a table in MySQL that has 3 fields and I want to
I inherited MYSQL database that has lots of tables with data like CREATE TABLE
I have this MySQl database that has a table which contains a column that
I inherited a mysql database that has a table with columns like this: object_id,
MySQL has a RENAME TABLE statemnt that will allow you to change the name
I have a mysql table that has two fields that store the same type
I have a MySQL table which has about 30 columns. One column has empty
My MySQL database table has dates stored in the MySQL format (YYYY-MM-DD). I need
Possible Duplicate: MySQL latitude and Longitude table setup I know this question has probably

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.