SQL-query with max lenght

SQL-query with max lenght

Postby Marc Vanzegbroeck » Thu Jul 25, 2013 5:38 pm

Hi,

I know this is not the right forum for SQL-query's, bet mayme someone know the result.

I have a SQL-table (tagnames) like

Code: Select all  Expand view
PARAMETER  INHOUD
---------  ------
TAGNAME    AI123
PTDESC     THIS IS A TEST
KEYWORD    A
TAGNAME    AI1231
PTDESC     THIS IS AN OTHER TEST
KEYWORD    ABBB
TAGNAME    AI123456
PTDESC     THIS IS A TEST
KEYWORD    AQ


I would like to return an unique record per PARAMETER and the maximum lenght of field INHOUD
It sould be something like
Code: Select all  Expand view
PARAMETER  INHOUD
---------  ------
TAGNAME    8
PTDESC     21
KEYWORD    4


I already have tried with
Code: Select all  Expand view
SELECT parameter,inhoud,length(inhoud) as vlen  from tagnames group by parameter

But this give me the unique PARAMETERS, but not the maximum of the field-lengt of INHOUD

The same with
Code: Select all  Expand view
SELECT parameter,inhoud,max(length(inhoud)) as vlen  from tagnames group by parameter


How can I do this?
Thanks,
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: SQL-query with max lenght

Postby Enrico Maria Giordano » Thu Jul 25, 2013 8:49 pm

Marc,

Marc Vanzegbroeck wrote:
Code: Select all  Expand view
SELECT parameter,inhoud,length(inhoud) as vlen  from tagnames group by parameter


The query below works fine with Access:

Code: Select all  Expand view
SELECT Parameter, Max( Len( Inhoud ) ) AS VLen FROM TagNames GROUP BY Parameter


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: SQL-query with max lenght

Postby Marc Vanzegbroeck » Fri Jul 26, 2013 6:02 am

Enrico Maria Giordano wrote:Marc,

Marc Vanzegbroeck wrote:
Code: Select all  Expand view
SELECT parameter,inhoud,length(inhoud) as vlen  from tagnames group by parameter


The query below works fine with Access:

Code: Select all  Expand view
SELECT Parameter, Max( Len( Inhoud ) ) AS VLen FROM TagNames GROUP BY Parameter


EMG


Enrico,

You are correct
Code: Select all  Expand view
SELECT parameter,imax(length(inhoud)) as vlen  from tagnames group by parameter

works fine also with SQLite.
I think I have made a mistake while testing, I used instead of GROUP BY, ORDER BY because i was thinking to order it on length from high to low and than Group them, but GROUP BY and ORDER BY doesn't work in the same select..
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 74 guests