I have a table people with (among others) fields givenName and gender. I want to update all those rows with gender=NULL according to best guesses based on other rows.
That is, if there are teh following rows
"John", NULL
"Jane", NULL
"Sam", NULL
"Alex", NULL
"Jack", NULL
"John", "male"
"John", "male"
"Jane", "female"
"Sam", "female"
"Sam", "male"
"Alex", "female"
I want to produce the following changes:
"John", "male"
"Jane", "female"
"Sam", NULL
"Alex", "female"
"Jack", NULL
...
So John is correctly identified as male, Jane as female, whereas it is left unclear whether Sam is a Samantha or a Samuel. I am aware of the shortcomings of my approach (namely, Alex might in reality be male, and the well-known male name Jack is not recognized as such), but still I wonder if my goal can be achieved with a single SQL query?
If it weren't for the mixed cases (such as "Sam"), I suppose that UPDATE people A, people B SET A.gender = B.gender WHERE A.givenName=B.givenName AND A.gender IS NULL and B.gender IS NOT NULL should do it ...
CREATE TEMPORARY TABLEwith the non-ambiguous names?