Ask a Question related to MySQL, Design and Development.
-
aljosa.mohorovic@gmail.com #1
"group by" - order of rows in group
this is simple example:
TABLE SCHEMA:
create table my_table(
id int unsigned not null auto_increment primary key,
project varchar(255) not null,
title varchar(255) not null
);
TABLE DATA:
1 | project_1 | revision_1
2 | project_2 | revision_1
3 | project_1 | revision_2
QUERY:
select id,project,title from my_table group by project order by title
asc;
RESULT:
1 | project_1 | revision_1
2 | project_2 | revision_1
WHAT I WANT:
2 | project_2 | revision_1
3 | project_1 | revision_2
MY PROBLEM:
from rows in groups, example for "project_1" group rows:
1 | project_1 | revision_1
3 | project_1 | revision_2
i want row with highest id to be part of result.
i currently achieve this by calling "alter table researches order by id
desc" before select.
Aljosa Mohorovic
aljosa.mohorovic@gmail.com Guest
-
Change settings to "Always Allow" via Group Policy
We upgraded our Flash Players from v6 to v8 (I know v9 is out we haven't go there yet) a couple months ago, and we've just noticed that we can not... -
cfoutput cfquery "group processing" error
I am attempting to write data to an html table from three different Access tables. I have three (3) queries in the cftransaction, each later query... -
cfgrid inside a <cfoutput query="myQuery" group="GROUP">
Is it possible to use a cfgrid inside a cfoutput with a query and a group. When I try do that I get the following error: INVALID_CHARACTER_ERR:... -
Elements "pasted inside" change position when parent group is re-sized
Anyone else have this problem? I've got a fairly complex logo -- all vector elements created in FH (11.01). The group includes several... -
Debian Equivalent of Group "Wheel"?
Dear List, Iım a newcomer and tried to find this topic in the archives, but I had trouble using Glimpse to filter out ³wheel mouse². I hope Iım... -
strawberry #2
Re: "group by" - order of rows in group
[email]aljosa.mohorovic@gmail.com[/email] wrote:
This question gets asked a lot!> this is simple example:
>
> TABLE SCHEMA:
> create table my_table(
> id int unsigned not null auto_increment primary key,
> project varchar(255) not null,
> title varchar(255) not null
> );
>
> TABLE DATA:
> 1 | project_1 | revision_1
> 2 | project_2 | revision_1
> 3 | project_1 | revision_2
>
> QUERY:
> select id,project,title from my_table group by project order by title
> asc;
>
> RESULT:
> 1 | project_1 | revision_1
> 2 | project_2 | revision_1
>
> WHAT I WANT:
> 2 | project_2 | revision_1
> 3 | project_1 | revision_2
>
> MY PROBLEM:
> from rows in groups, example for "project_1" group rows:
> 1 | project_1 | revision_1
> 3 | project_1 | revision_2
> i want row with highest id to be part of result.
>
> i currently achieve this by calling "alter table researches order by id
> desc" before select.
>
> Aljosa Mohorovic
Here's a generic answer.
SELECT t1 . *
FROM table1 t1
LEFT JOIN table1 t2 ON t1.col1 = t2.col1
AND t1.col2 < t2.col2
WHERE t2.col2 IS NULL;
strawberry Guest



Reply With Quote

