Question

I am performing a soundex query on a table of users. A subquery of users is provided as a comma separated list of strings.

I want to do something akin to the following, but I cannot find the write syntax to make this work.

select * from ((Select soundex(concat(fname, lname)) t, * from users)
Union
(Select soundex(fname) t, * from users)
Union
(Select soundex(lname) t, * from users)) xusers
where t in (select soundex([column]) from ('Name 1', 'Name 2', 'Name 3', 'Name N-1', 'Name N'))

Later I plan to optimize this query by having a table with the soundex values mapped to column id's, however, I'm not sure now I can reference an anonymous column when my subquery is a comma delimited list? How do I add an alias, or how can convert this list to a list of soundex values to perform comparisons with?

Was it helpful?

Solution

I was able to accomplish this by utilizing a temporary table inserting the list into my temporary table and then joining the temporary table with my query table to get the desired result.

create temporary table searchvalues (name char(250));
insert into searchvalues values ('Name 1'),('Name 2');
select distinct id from users inner join searchvalues on soundex(fname) = soundex(name) or     soundex(lname) =soundex(name) or soundex(concat(fname,lname)) = soundex(name);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top