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
 Select comparing rows

Author  Topic 

MaskdBagel
Starting Member

1 Post

Posted - 2010-02-03 : 19:00:04
I'm a rookie's rookie with SQL, and I'm trying what should be a pretty simple select.

My table has 5 columns: FragmentNum, FragmentText, LocaleID, RevisionNum, and Status.

In plain language, what I need to find is this:
Select all rows from dbo.viewFragmentTextStatus
Where the FragmentText column contents for LocaleID 9 match the column contents for any other LocaleID
And where the RevisionNum evaluated for the criteria above is the highest of all those available for each LocaleID
And where the status = active

Basically, if things are set up the way they should be, the most recent text in locale 9 should be in English, and the most recent text for the other locale IDs should be in their respective languages, not in English. I'm trying to find fragment IDs where that isn't the case.

Is there some relatively simple syntax to do that?

Thanks!!!

Kent

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-04 : 03:25:52
do you mean this?

SELECT FragmentText
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY LocaleID ORDER BY RevisionNum DESC) AS rn,FragmentNum, FragmentText, LocaleID, RevisionNum, Status
FROM dbo.viewFragmentTextStatus
)t
WHERE rn=1
GROUP BY FragmentText
HAVING COUNT(DISTINCT LocaleID) >1
AND SUM(CASE WHEN LOcaleID=9 THEN 1 ELSE 0 END) <> 0
Go to Top of Page
   

- Advertisement -