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
 Trying to join within a table

Author  Topic 

sqltry
Starting Member

1 Post

Posted - 2014-08-27 : 20:57:08
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-08-28 : 08:45:35
[code]SELECT
PrimaryId,
MAX(CaseKey) AS CaseKey,
MAX(BottleKey) AS BottleKey
FROM
YourTable
GROUP BY
PrimaryId;[/code]
Go to Top of Page
   

- Advertisement -