I created alternate names for wives so I can find the wife with her married name.
I put the given and maiden name in the given for the alternate name. I put her husband’s surname in surname. I use Married as Name Type, Mrs. As Prefix and the husbands given name with parenthesis around it as the suffix.

I am using the following query to get the alternate names: (See Pic 1)
Pic 1.jpg
It works great if there is only one alternate name. It is a problem if there is more than one alternate name for each husband as displayed in Pic 1.

Pic 2.jpg
This is the print screen of Rootsmagic. (See Pic 2)

Pic 3.jpg
If I do a data view of the nametable and do a custom on ownerid of 590, I get the following: (See Pic 3)

Pic 4.jpg
If I do a data view of the familytable and do a custom on ownerid of 590, I get the following: (See Pic 4)

Pic 5.jpg
How do I get the original query to display the correct husband with the wife like displayed below? (See Pic 5)

Pic 6.jpg
I copy all of the results of the query into a spreadsheet to verify there aren’t any typos in the alternate name. (See Pic 6)

Is it possible to create the query to get the results contained in the spreadsheet? (Column O and Column P)

How could I put a where statement in thee query to select only certain ownerid's? I need to be able to hard code it and to be able to input the ownerid.