GROUP BY mysql

5 pts.
Tags:
MySQL
MySQL Database
MySQL query
Hi

I have started working with a mySQL databse.

I need a query that will either make use of "DISTINCT" or "GROUP BY" but that selectes the record that has the highest 'VersionNumber'

Can anybody suggest how I would achieve this?

Thanks in advance.

ASKED: June 7, 2012  8:10 AM
UPDATED: June 22, 2012  4:01 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

What column are you wanting to group by? I’ll just call it groupColumn for now, ok? So taking that into account, here is what I’d do:

SELECT groupColumn, max(VersionNumber) FROM tableName GROUP BY groupColumn;

Hope that help!

Ron
<a href=”http://mysqlexchange.com”>

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • BigKat
    you can try something like this, but we probably need more information about what you want to query to be able to help you fully
    select * from fpitmmas where (itvndn, itmnum)
    in(select itvndn, max(itmnum) from fpitmmas group by itvndn) 
    7,565 pointsBadges:
    report
  • STCPD
    I'm sorry, I'm new to crystal and that just went way over my head. So in the [code] part which code and I supposed to put at the beginning and which at the end?
    15 pointsBadges:
    report
  • TomLiotta
    ...to put at the beginning and which at the end? Beginning and end of what? What exactly is your question? Are you needing training on how to use both Crystal Reports and MySQL? Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following