Well, I thought I read you couldn't put min in an order by clause, but I may be confusing that with subselects.
At any rate, I get an error when I do that:
2009-01-29 17:23:28,211: [51204] util.JDBCExceptionReporter SQL Error: -67, SQLState: 37000
2009-01-29 17:23:28,211: [51204] util.JDBCExceptionReporter SQL Error: -67, SQLState: 37000
2009-01-29 17:23:28,211: [51204] util.JDBCExceptionReporter Not in aggregate function or group by clause: org.hsqldb.Expression@163d118 in statement [select distinct ownerships0_.id as id27_, ownerships0_.version as version27_, ownerships0_.country_id as country3_27_, ownerships0_.created_by_id as created4_27_, ownerships0_.date_created as date5_27_, ownerships0_.is_complete as is6_27_, ownerships0_.last_updated as last7_27_, ownerships0_.updated_by_id as updated8_27_ from ownership_snapshot_series ownerships0_ inner join ownership_snapshot snapshots1_ on ownerships0_.id=snapshots1_.series_id inner join ownership_snapshot_network networks2_ on snapshots1_.id=networks2_.ownership_snapshot_networks_id inner join network network3_ on networks2_.network_id=network3_.id group by ownerships0_.id order by min(network3_.network_id)]
2009-01-29 17:23:28,211: [51204] util.JDBCExceptionReporter Not in aggregate function or group by clause: org.hsqldb.Expression@163d118 in statement [select distinct ownerships0_.id as id27_, ownerships0_.version as version27_, ownerships0_.country_id as country3_27_, ownerships0_.created_by_id as created4_27_, ownerships0_.date_created as date5_27_, ownerships0_.is_complete as is6_27_, ownerships0_.last_updated as last7_27_, ownerships0_.updated_by_id as updated8_27_ from ownership_snapshot_series ownerships0_ inner join ownership_snapshot snapshots1_ on ownerships0_.id=snapshots1_.series_id inner join ownership_snapshot_network networks2_ on snapshots1_.id=networks2_.ownership_snapshot_networks_id inner join network network3_ on networks2_.network_id=network3_.id group by ownerships0_.id order by min(network3_.network_id)]
Funny thing is, when I put the generated SQL into my database's query editor, it works....
select
distinct ownerships0_.id as id27_,
ownerships0_.version as version27_,
ownerships0_.country_id as country3_27_,
ownerships0_.created_by_id as created4_27_,
ownerships0_.date_created as date5_27_,
ownerships0_.is_complete as is6_27_,
ownerships0_.last_updated as last7_27_,
ownerships0_.updated_by_id as updated8_27_
from
ownership_snapshot_series ownerships0_
inner join
ownership_snapshot snapshots1_
on ownerships0_.id=snapshots1_.series_id
inner join
ownership_snapshot_network networks2_
on snapshots1_.id=networks2_.ownership_snapshot_networks_id
inner join
network network3_
on networks2_.network_id=network3_.id
group by
ownerships0_.id
order by
min(network3_.network_id)
|