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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:16:47+00:00 2026-06-13T12:16:47+00:00

I have a MySQL table: id int a varchar b varchar c varchar version

  • 0

I have a MySQL table:

id       int
a        varchar
b        varchar
c        varchar
version  int
active   bool

I want to grab the max version group by a, b and c, so I have the following query to do that:

select a, b, c, max(version) as version from mytbl where active = 1 group by a, b, c

I am using Datamapper with Sinatra. The above table model name is “mytbl”.
What would be the datamapper equivalent of the above query?

  • 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-06-13T12:16:48+00:00Added an answer on June 13, 2026 at 12:16 pm

    I got it 🙂

    mytbl.aggregate(:version.max, :active => 1, :fields => [:a, :b, :c], :unique => true, :order => nil)
    

    or

    mytbl.aggregate(:version.max, :conditions => [ 'active = ?', 1], :fields => [:a, :b, :c], :unique => true, :order => nil)
    

    However I could not find a way to alias max(version) as version. It returns max(version) as the column name. Thats not a big deal 😉

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

Sidebar

Related Questions

I have the following MySQL (version 5.1) table (InnoDB): Username varchar(50) Sequence int(11) FileType
I have a mysql table structure like that: id int primary key name varchar
I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment
I have a table message in mysql id(bigint) sender(int) receiver(int) message(varchar) 1 42 420
I have a MySQL table that looks like this: `id` int(10) unsigned NOT NULL
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have the following script to create a table in MySQL version 5.1 which
I have the following table in MySQL version 5.5.24 DROP TABLE IF EXISTS `momento_distribution`;
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have this in a MySQL db: table Message sender_id int recipient_id int created

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.