1

I have a table

Table

I am using the following query

select max(dblVersion),sName,fCompleted,ixLastModifiedBy,dtCreatedAt,dtLastModifiedAt,fStatus from tblechecklisttemplateversion group by ixTemplate

I am getting the below table as output Table2

The row values of other columns are not corresponding to the dblVersion Column .. How to display the corresponding row values

Manoj Nayak
  • 2,449
  • 9
  • 31
  • 53

2 Answers2

1

Try this

SELECT 
   a.dblVersion,
   a.sName,
   a.fCompleted,
   a.ixLastModifiedBy,
   a.dtCreatedAt,
   a.dtLastModifiedAt,
   a.fStatus 
FROM 
   tblechecklisttemplateversion a
JOIN (
    SELECT 
        ixTemplate,
        max(dblVersion) as dblVersion 
    FROM 
        tblechecklisttemplateversion 
    GROUP BY 
        ixTemplate) as b
ON 
    a.ixTemplate=b.ixTemplate and a.dblVersion=b.dblVersion
bitoshi.n
  • 2,278
  • 1
  • 16
  • 16
0

This might help you..

MySQL - Get row number on select

changed query -

  SELECT 0 INTO @x;
  select (@x:=@x+1) as  
  rownumber,max(dblVersion),sName,fCompleted,ixLastModifiedBy,dtCreatedAt,
  dtLastModifiedAt,fStatus 
  from tblechecklisttemplateversion group by ixTemplate
Community
  • 1
  • 1
Sanath
  • 4,774
  • 10
  • 51
  • 81