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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:42:12+00:00 2026-05-13T13:42:12+00:00

I am using mysql for database. I have to find the distinct latest result

  • 0

I am using mysql for database.
I have to find the distinct latest result for a customer having different values for ContentPrvdr field.
I am using following sql query:

SELECT  distinct ContentPrvdr,LocalDatabaseId,Website,BusID,LastUpdated,
UserCat1Rank_Local,UserCat1Count_Local,Citations,PhotoCount,
VideoCount,Cat_Count FROM local_database WHERE CMCustomerID=10  
ORDER BY LocalDatabaseId,LastUpdated LIMIT 0,3

to find the result,but it will return three result having same value for ContentPrvdr.But i want different value results for ContentPrvdr.
Here are the sample data for test.

LocalDatabaseId     CMCustomerID    FranchiseName   ContentPrvdr    BusName     ConvBusName     KeyWBizName     KeyWCat     Website     LocationNmbr    PhoneLoc    StreetLoc   Cat_Count   Description_Local   Citations   PhotoCount  VideoCount  UserContent 
41  15  2 For 1 Pizza Co    bing    2 For 1 Pizza Co    2 FOR 1 PIZZA CO    2 For 1 Pizza Co, Los Angeles, CA   Pizza Restaurant, Los Angeles, CA   http://st1.map  1   3232699421  3480 E CESAR E CHAVEZ AVENUE    1       0   0   0   0
41  15  2 For 1 Pizza Co    bing    2 For 1 Pizza Co    2 FOR 1 PIZZA CO    2 For 1 Pizza Co, Los Angeles, CA   Pizza Restaurant, Los Angeles, CA   NULL    1   3232699421  3480 E CESAR E CHAVEZ AVENUE    1       0   0   0   0
56  15  2 For 1 Pizza Co.   Google  2 For 1 Pizza Co.   2 FOR 1 PIZZA CO    2 For 1 Pizza Co, Los Angeles, CA   Pizza Restaurant, Los Angeles, CA   Not Specified   1   2137494515  2528 S. FIGUEROA STREET 2       0   3   0   0
56  15  2 For 1 Pizza Co.   Google  2 For 1 Pizza Co.   2 FOR 1 PIZZA CO    2 For 1 Pizza Co, Los Angeles, CA   Pizza Restaurant, Los Angeles, CA   Not Specified   1   2137494515  2528 S. FIGUEROA STREET 2   Fresh N Ho  23  2       1
65  15  2 For 1 Pizza Co    Google  2 For 1 Pizza Co    2 FOR 1 PIZZA CO    2 For 1 Pizza Co, Los Angeles, CA   Pizza Restaurant, Los Angeles, CA   Not Specified   1   3232699421  3480 EAST CESAR E CHAVEZ AVENUE 1       0   0   0   0
65  15  2 For 1 Pizza Co    Google  2 For 1 Pizza Co    2 FOR 1 PIZZA CO    2 For 1 Pizza Co, Los Angeles, CA   Pizza Restaurant, Los Angeles, CA   Not Specified       3232699421‎ 3480 EAST CESAR E CHAVEZ AVENUE 1       25  0   0   1
126 15  2 For 1 Pizza Co    yellopages  2 For 1 Pizza Co    2 FOR 1 PIZZA CO    2 For 1 Pizza Co, Los Angeles, CA   Pizza Restaurant, Los Angeles, CA   http://www.yellow   1   5628610936  5720 IMPERIAL HWY STE Q 2   EATING PLACE    0   0   0   0
126 15  2 For 1 Pizza Co    yellopages  2 For 1 Pizza Co    2 FOR 1 PIZZA CO    2 For 1 Pizza Co, Los Angeles, CA   Pizza Restaurant, Los Angeles, CA   http://www.yello    1   5628610936  5720 IMPERIAL HWY STE Q 2   EATING PLACE    0   0   0   0

Please Some body help me how can i get this result with distinct ContentPrvdr values .

Thanks in advance

  • 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-13T13:42:12+00:00Added an answer on May 13, 2026 at 1:42 pm

    You probably want something like this. I’m assuming that (ContentPrvdr, LocalDatabaseId, LastUpdated, CMCustomerID) is unique. If this is not the case, you need to specify something that is unique on your database as it doesn’t appear to have any obvious primary key.

    SELECT T4.* FROM (
        SELECT T2.ContentPrvdr, T2.LocalDatabaseId, MIN(T2.LastUpdated) AS LastUpdated
        FROM (
            SELECT ContentPrvdr, MIN(LocalDatabaseId) AS LocalDatabaseId
            FROM local_database
            WHERE CMCustomerID = 10
            GROUP BY ContentPrvdr) AS T1
        JOIN local_database AS T2
        ON T1.ContentPrvdr = T2.ContentPrvdr
        AND T1.LocalDatabaseId = T2.LocalDatabaseId
        WHERE CMCustomerID = 10
        GROUP BY ContentPrvdr, LocalDatabaseId
    ) AS T3
    JOIN local_database AS T4
    ON T3.ContentPrvdr = T4.ContentPrvdr
    AND T3.LocalDatabaseId = T4.LocalDatabaseId
    AND T3.LastUpdated = T4.LastUpdated
    WHERE CMCustomerID = 10
    ORDER BY LocalDatabaseId, LastUpdated
    LIMIT 3
    

    This is the data I used to test that the query works:

    CREATE TABLE local_database (
        CMCustomerID int NOT NULL,
        ContentPrvdr int NOT NULL,
        LocalDatabaseId int NOT NULL,
        LastUpdated int NOT NULL,
        Website int NOT NULL);
    INSERT INTO local_database
    (CMCustomerID, ContentPrvdr, LocalDatabaseId, LastUpdated, Website)
    VALUES
    (10, 1, 2, 2, 1),
    (11, 1, 2, 2, 1),
    (11, 1, 1, 1, 2),
    (11, 1, 2, 1, 3),
    (10, 2, 2, 2, 4),
    (10, 2, 1, 3, 5),
    (10, 2, 1, 2, 6),
    (11, 3, 3, 3, 7),
    (10, 4, 4, 4, 8),
    (10, 5, 5, 5, 9);
    

    And this is the result I get for this data:

    10, 2, 1, 2, 6
    10, 1, 2, 2, 1
    10, 4, 4, 4, 8
    

    If this is not correct, please suggest adjustments to the test data and/or expected result to show what you do want.

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

Sidebar

Related Questions

I have a couple of scripts that interact with a MySQL database using ActiveRecord
I have a MySQL database table with two columns that interest me. Individually they
My webapp is hosted on a unix server using MySQL as database. I wrote
I'm fairly new to PHP and have built a medium sized website using standard
Am fairly new to using MySQL and a total novice at Perl but am
I did find other posts similar to this, but wanted a little extra information
What is the best way trying to get a text search function using nhibernate?
I have a script that sends out emails every minute. When it starts its
I have the below db model: from datetime import datetime class TermPayment(models.Model): # I

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.