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
 Trying to join within a table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqltry
Starting Member

1 Posts

Posted - 08/27/2014 :  20:57:08  Show Profile  Reply with Quote
So if an item is a bottle, it will have a unique BottleKey and Null for CaseKey and if an item is a Case, it will have a unique CaseKey and Null for BottleKey. However, the PrimaryIDs are the same for both the bottle and case. I get the results to look like this:

Bottlekey CaseKey PrimaryID
4754 NULL ABC-234
NULL 5465 ABC-234
.... .... .......

Is there a way to get the result sorted by Primary ID?

So that the rows are halved from what we have in the table above and the results look like

PrimaryID CaseKey BottleKey
ABC-234 5465 4754


Thanks

James K
Flowing Fount of Yak Knowledge

3653 Posts

Posted - 08/28/2014 :  08:45:35  Show Profile  Reply with Quote
SELECT
	PrimaryId,
	MAX(CaseKey) AS CaseKey,
	MAX(BottleKey) AS BottleKey
FROM
	YourTable
GROUP BY
	PrimaryId;
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.05 seconds. Powered By: Snitz Forums 2000