SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 table related returns products duplicated and once
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

marcobranco1975
Starting Member

2 Posts

Posted - 02/08/2013 :  10:47:16  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3587 Posts

Posted - 02/08/2013 :  10:55:00  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000