On my websites, I have some filters to search for data. The data is served through various following 4 tables:
1. tb_contacts
2. tb_data_fields
3. tb_data_values
4. tb_data_cat_options
Now, I want to do following queries:
- How to fetch all "Sachin" from "India"?
- How to fetch all "Sachin" from "India" which work in "Software" industry?
- How to fetch all "Sachin" from "Delhi"?
I am trying below query to fetch first result, but don't know how to expand this query to get more combination of result or narrow down the search using more filters:
SELECT DISTINCT c.*
, df.field_name
, dv.field_value
FROM tb_contacts c
JOIN tb_data_values dv
ON c.contact_id = dv.contact_id
JOIN tb_data_fields df
ON dv.field_id = df.field_id
WHERE c.contact_name = "Sachin Sharma"
AND dv.field_value = "India"
Output
Guys, please help me on sorting out this issue.
Comments
Post a Comment