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
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.
This is the data I used to test that the query works:
And this is the result I get for this data:
If this is not correct, please suggest adjustments to the test data and/or expected result to show what you do want.