Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Dear all,My table structure is like this..id | name | EOD_ID | EOD_date| EDM_batch1 a 222 201001 TC1 b 203 0 TC I need to select only one row even if there a non matching records for other fields except ID based on maximun EOD_date.How can we select this max record from the above table even though there is non matching rows exist.
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2010-02-09 : 10:39:14
Do you mean this?
select * from(select row_number() over (partition by id order by EOD_date desc) as rownum, name, EOD_ID,EOD_date,EDM_batch from your_table)dtwhere rownum=1
No, you're never too old to Yak'n'Roll if you're too young to die.
gangadhara.ms
Aged Yak Warrior
549 Posts
Posted - 2010-02-09 : 10:43:37
becous i am using this query result to join some other table as well..is this okie withgood performance ?? I am using this query but still its not fetching the only one record.select id , name ,max(EOD_date) Creation_Date ,EDM_Batch from TES_TRANSACTIONSwhere EOD_ID is not nullor EOD_date <> 0or EDM_batch <> 0or id <> 0or name <> 0
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2010-02-09 : 10:54:46
Your query gives the max(EOD_date) from the table regarding the where clause but with no relation to the id or other columns.About performance I can't say something without any information.Did you try my solution?No, you're never too old to Yak'n'Roll if you're too young to die.
gangadhara.ms
Aged Yak Warrior
549 Posts
Posted - 2010-02-09 : 11:31:29
In your query i need max EOD_date ??
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-02-09 : 11:40:57
[code]select t.*from table tinner join (select id,max(EOD_date) AS Recent from table group by id)t1on t1.id=t.idand t1.Recent = t.EOD_date[/code]