0

I have a big database table called pricing. The fields are following:

id code description rrp buy stock date distributor vendor version

User select the vendor field only. version field can be vary for each distributor. I need to display all the details from pricing table but only the recent version of each distributor. For that I am trying to get all distributors and it's recent version. I have coded as below:

$all_distributors=mysql_query("SELECT `distributor`,MAX(`version`) as `version` FROM `pricing` WHERE `vendor`='$vendor_id' GROUP BY `distributor`,`version`",$con);
while($all_dist= mysql_fetch_array($all_distributors))
{
    $d_ID=$all_dist['distributor'];
    $d_version=$all_dist['version'];
    echo $d_ID."-".$d_version."<br/>";
}

But the output shows all versions of distributors, like below:

distributor-version
1-20131107V1
1-20131108V2
2-20131108V1

How can I display only the latest version of each distributor?

So the output should be:

1-20131108V2
2-20131108V1

1 Answer 1

1

Your grouping by distributor, version makes it so that any unique combo of distributor and version is a separate group. This is what is being displayed in your output. I think you only want to group by distributor if I'm reading the question right.

Sign up to request clarification or add additional context in comments.

1 Comment

huh! that's correct. Thanks! I have been thinking other ways..you saved my day :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.