I have this query:
SELECT
c.ID, c.Firstname, c.lastname, c.BDaY, c.gender,
cp.code, cp.Citizenship, r.race, e.ethnicity
FROM
Client AS C (nolock)
JOIN
Citizenship AS cp (nolock) ON c.ID = cp.client_ID
JOIN
Race AS r (nolock) ON c.ID = R.Client_ID
JOIN
Ethnicity AS E (nolock) ON E.Client_ID = c.ID
This query will return some of the client's names duplicated because they have different race and ethnicity.
Example:
ID |FirstName|Lastname| BDay | gender | code |citizenship| race | ethnicity
1 Pedram Salamati 01-20-1998 M 1 US citizen Middle-east Spanish
1 Pedram Salamati 01-20-1998 M 1 US Citizen Middle-east unknown
1 Pedram Salamati 01-20-1998 M 1 US Citizen Middle-east Brazilian
2 Jesse Albert 03-05-1982 F 1 US Citizen African not Spanish
2 Jesse Albert 03-05-1982 F 1 US Citizen American not Spanish
I was wondering if there is any way to say if race is not = than Race should be Multiracial and if ethnicity Is not = to each other for same Id choose the last updated one.
PS.Ethnicity
has time stamp and I can use Max(e.LastUpdate)
I think maybe a sub query can help!
Any help or thought will be much appreciated!