I have this: A table where i have CONTACTS, each contact is linked to a COMPANY, the companies are in another table. Then i have the INFORMS table in where i have a list of informs with some data and everyone is linked to a CONTACT. I need to make a sql that filter that informs list but only show the informs of an specific COMPANY, so it has to search all the contacts that has the same COMPANY and show me the INFORMS of that company. Any ideas?
UPDATE:
Table COMPANY:
- id: 02 Name: Google
Table CONTACT:
- id: 01 Name: John Company: 02 - So is linked to Google
Table INFORMS:
- id: 01 Data: Some data Contact: 01 - So is linked to john
- id: 02 Data: Some data Contact: 01 - Another one linked to john
- id: 03 Data: Some data Contact: 02 - not linked to john
I need to make a search query that showme only the informs linked to GOOGLE, so all the Informs linked to contacts that has GOOGLE as company. SO Inform 01 and 02 I`m trying something like this but dont work:
$sql = "SELECT * FROM polar_companies WHERE id IN (SELECT * FROM polar_contacts WHERE Empresa = '$v_empresa');"
HERE I DONT KNOW HOT TO PERFORM A INFORM SEARCH
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo HERE I NEED THE INFORMS
}
} else {
echo "<p>No informs</p>";
}
select informs.* from informs, contact, company where informs.contact=contact.id and contact.company=company.idand company.id=?