Skip to content

Duplicate last row with group by query #13

@napcs

Description

@napcs

Using this query:

select distinct terms.id, count(workshops.id) as workshop_count, sum(workshops.time_spent)/3600 as term_time_spent, terms.semester, terms.year
from terms left join workshops on workshops.term_id=terms.id
and workshops.cancelled = 0
and workshops.visible = 1
and workshops.enabled = 1
where terms.id like '1'
group by terms.id, terms.semester, terms.year
order by terms.year

We're always getting one additional row, which is a duplicate row.

Table definitions are:

create_table "workshops", :force => true do |t|
  t.text     "prerequisites"
  t.integer  "department_id"
  t.integer  "seats"
  t.text     "comments"
  t.string   "number"
  t.integer  "offering_id"
  t.integer  "location_id"
  t.datetime "starts_at"
  t.datetime "ends_at"
  t.boolean  "visible"
  t.boolean  "enabled"
  t.datetime "created_at"
  t.boolean  "cancelled"
  t.boolean  "attendance_submitted"
  t.integer  "term_id"
end

create_table "terms", :force => true do |t|
 t.string  "semester"
 t.string  "year"
 t.boolean "is_current"
end

This seems like a fairly simple query, and we did run this through SQLServer 2005's console directly and received only one record.

Rails 2.3.2
Adapter version 2.2.19

Any help would greatly be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions