moody moody - 1 month ago 5
MySQL Question

mysql request retrieve data combined with 2 tables

U have three tables

enter image description here

I would like to request all persons, where the companyTypeID is for example '2'. How can I query that?

Answer

You could use the in operator:

SELECT *
FROM   persons
WHERE  CompanyId IN (SELECT CompanyId
                     FROM   company
                     WHERE  CompanyTypeId = 2)