I have a table structure like this (vertical design). I can have unlimited number of attributes (eg: city, phone etc.) for each user.
Table: tbl_UserAttributes
┌────────┬───────────┬────────────┐
| UserID │ FieldName │ Value |
├────────┼───────────┼────────────┤
│ 341 │ city │ MyCity1 │
│ 772 │ phone │ 1234567890 │
│ 033 │ city │ MyCity2 │
│ 044 │ sex │ M │
│ 772 │ firstname │ MyName │
│ --- │ --- │ --- │
└────────┴───────────┴────────────┘
I have to implement a search feature which should output rows which we apply query like this for a horizontally designed table:
SELECT
FieldName
FROM
tbl_UserAttributes
WHERE
city='%Mumbai%' AND
sex='M' AND ...
Please dont ask me to change the database design.
UPDATE: At present, I have a JOIN solution in place which is very slow and it hangs the server some times. Any alternate methods?