Having 3 tables:
1)name: companies, fields: company_id, company_name;
2)name: contacts, fields: contact_id, contact_name;
3)name: connections, fields: connection_id, contact_id, company_id;
I'm making multiple search. For example, I want to find companies called like "qwer" and contacts called like "abc". So my query will be:
$query="SELECT * FROM COMPANIES WHERE company_name RLIKE (qwer)"
Next step I'll make a massive with id of these companies. Next query will be like:
$query="SELECT * FROM connections WHERE company_id in (my massive)"
Making massive of contact_id from this selection and then making the last query:
$query="SELECT * FROM contacts WHERE contact_name RLIKE(abc) and id in(my massive)"
So, is it possible to make all this actions in one query or using less actions than I used?
As example, I need to find all companies called like "oogle" with contacts like "ith". As a result I need to get one company "Google" with two contacts: John Smith and Jenny Smith.
@Iqbal helps a lot, but I have one more table called addresses with two fields: id and street. And in table companies there is one more field called addresses_id. So I tried to get all info with such query:
select con.connection_id, com.company_name, ctx.contact_name
from addresses as add, connections as con
left join companies as com on con.company_id = com.company_id
left join contacts as ctx on con.contact_id = ctx.contact_id
where add.id=com.Legal_address
But it doesn't work, have a mistake: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add, Connections as con LEFT JOIN Companies as com on con.company_id = com.id LE' at line 1"