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.
Hi, i am using sql serveer 2008, and i have this problemI have 2 tables:Table: productsid_code int PKname_prod varchar(20)Table:versionsid_produto intversion int PK(id_produto, version)i need to show the list of products with the latest version.i made thisselect distinct id_code, name, max(version) from produtsleft join versions on id_produto = id_codegroup by versionbut don't work...any idea?Thanks in advance
James K
Master Smack Fu Yak Hacker
3873 Posts
Posted - 2013-02-08 : 10:55:00
You may be grouping by the wrong column:
SELECT p.id_code, p.name, MAX(v.version)FROM produts p left join versions v on v.id_produto = p.id_codeGROUP BY p.id_code, p.name