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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 table related returns products duplicated and once

Author  Topic 

marcobranco1975
Starting Member

2 Posts

Posted - 2013-02-08 : 10:47:16
Hi, i am using sql serveer 2008, and i have this problem

I have 2 tables:
Table: products
id_code int PK
name_prod varchar(20)

Table:versions
id_produto int
version int PK(id_produto, version)


i need to show the list of products with the latest version.

i made this

select distinct id_code, name, max(version) from produts
left join versions on id_produto = id_code
group by version

but 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_code
GROUP BY
p.id_code,
p.name
Go to Top of Page
   

- Advertisement -