I have some sort of logic/sql challenge. I have two tables that hold user data and are related by a id. I would like to select the count of rows based on conditions from the two tables.
Here are my tables.
table one
t_contacts
id | name | tel | profession | email | sex | city | state |
int | varchar | varchar | int | varchar | char | varchar | varchar |
table two
t_contacts_meta
cid | interest |
int (t_contact_id) | varchar |
from the table, contacts are stored on the t_contacts
table and their interest stored on the t_contacts_meta
table.
One contact could have multiple interests.
My issue is the SQL query. example
SELECT COUNT(*) as count
FROM t_contacts
where `state`='$state'
AND `profession`='$profession'
AND `sex`='$sex'
AND (
`t_contacts_meta.interest`='$interest_1'
OR `t_contacts_meta.interest`='$interest_2
OR `t_contacts_meta.interest`='$interest_n'
)
The sql i provided above is not my working code its just an example. I dont even know how to go about the query.
Thanks for the help :)