I have data like this. Where sometimes there are 2 records, 1 with a mailing address & a non-mailing address, sometimes there is only 1 record and it could be either a mailing address or a non-mailing address.
UniqueID,FirstName,LastName,DOB,House Number,City,State,Mailing
4444,George,Jetson,10/10/55,800,Orbit City,Space,0
4444,George,Jetson,10/10/55,555,Orbit City,Space,1
5555,Fred,Flintstone,12/12/04,88,Bedrock,PH,0
5555,Fred,Flintstone,12/12/04,100,Bedrock,PH,1
6666,Barney,Rubble,7/7/07,999,Bedrock,PH,0
7777,Jonny,Quest,5/30/64,343,Action City,KS,1
I'm trying to make a query that will return 1 row for each person and prefer the mailing address if it exists. So ideally the query would return these records
4444,George,Jetson,10/10/55,555,Orbit City,Space,1
5555,Fred,Flintstone,12/12/04,100,Bedrock,PH,1
6666,Barney,Rubble,7/7/07,999,Bedrock,PH,0
7777,Jonny,Quest,5/30/64,343,Action City,KS,1
Does anyone have any suggestions, based on some of the articles I've been reading I am thinking maybe I need to have a subquery? I was getting stuck at the OVER PARTITION BY part in the examples I was reading, or should I have some sort of IF statement? I'm kind of new to SQL, so thanks for any direction or help.