I have already asked here Query Logic SQL and didn't get a response(could be with the presentation of my data) I really hope someone can take a look at this and provide their input on how to get this done. would highly appreciate any help.
I have a sql table data that looks like
users table
id | name     |
_______________
 1 | John     |
 2 | Mary     |
 3 | Charles  |
 4 | Mike     |
 5 | Lucy     |
 6 | Debbie   |
pairing table:
main_id | pair_id   | 
_____________________
  1     |   2       |      
  1     |   3       |   
  2     |   4       |   
  2     |   5       |   
  3     |   6       |     
  3     |   1       |   
when rendering output to user, my html table would look like this, using group_by groupconcat in sql.
main_name | paired_names
  John    |   Mary, Charles
  Mary    |   Mike, Lucy
  Charles |   Debbie, John
Now,the problem is during searching(wildcard search)
say the user will input "Charles"...
The output needs to be:
main_name | paired_names
  John    |   Mary, Charles
  Charles |   Debbie, John
since its going to do a wildcard search in both columns in the pair table.
For now, what i do is i manipulate the result set from the database but this has pagination and been advised that it will affect system performance if i query all data then manipulate after.
I hope someone will be kind enough to provide their advice on how to get this done.
I can provide further details if needed.
Looking forward to hear from you.