title: Query for any person has any account of type x
body: <p>Imagine I have two tables, Person and Account, a person can have accounts (type 1 and/or 2).
  I'd like to get a list of people who have at least one type 1 account, and also get a list of people who don't have a type 1 account. I'm using Query #1 and #2 for this respectively but I think I'm doing something is wrong because the results do not match.</p>
  <p><strong>Schema (MySQL v5.7)</strong></p>
  <pre><code>CREATE TABLE Person (
    `PersonId` INTEGER,
    `Name` VARCHAR(5)
  );
  
  INSERT INTO Person
    (`PersonId`, `Name`)
  VALUES
    ('1', 'Leo'),
    ('2', 'Natan'),
    ('3', 'Vera'),
    ('4', 'Julio'),
    ('5', 'Mary');
  
  CREATE TABLE Accounts (
    `AccountId` INTEGER,
    `PersonId` INTEGER,
    `Type` INTEGER
  );
  
  INSERT INTO Accounts
    (`AccountId`, `PersonId`, `Type`)
  VALUES
    ('1', '1', '0'),
    ('2', '1', '1'),
    ('3', '2', '0'),
    ('4', '2', '0'),
    ('5', '3', '1'),
    ('6', '4', '0'),
    ('7', '1', '0'),
    ('8', '2', '0');
  </code></pre>
  <hr />
  <p><strong>Query #1</strong></p>
  <pre><code>SELECT * FROM Person AS PD
  LEFT JOIN Accounts AS AC ON AC.PersonId = PD.PersonId
  WHERE AC.Type = 1;
  </code></pre>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>PersonId</th>
  <th>Name</th>
  <th>AccountId</th>
  <th>PersonId</th>
  <th>Type</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>Leo</td>
  <td>2</td>
  <td>1</td>
  <td>1</td>
  </tr>
  <tr>
  <td>3</td>
  <td>Vera</td>
  <td>5</td>
  <td>3</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div><hr />
  <p><strong>Query #2</strong></p>
  <pre><code>SELECT * FROM Person AS PD
  LEFT JOIN Accounts AS AC ON AC.PersonId = PD.PersonId
  WHERE AC.Type = 0;
  </code></pre>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>PersonId</th>
  <th>Name</th>
  <th>AccountId</th>
  <th>PersonId</th>
  <th>Type</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>Leo</td>
  <td>1</td>
  <td>1</td>
  <td>0</td>
  </tr>
  <tr>
  <td>1</td>
  <td>Leo</td>
  <td>7</td>
  <td>1</td>
  <td>0</td>
  </tr>
  <tr>
  <td>2</td>
  <td>Natan</td>
  <td>3</td>
  <td>2</td>
  <td>0</td>
  </tr>
  <tr>
  <td>2</td>
  <td>Natan</td>
  <td>4</td>
  <td>2</td>
  <td>0</td>
  </tr>
  <tr>
  <td>2</td>
  <td>Natan</td>
  <td>8</td>
  <td>2</td>
  <td>0</td>
  </tr>
  <tr>
  <td>4</td>
  <td>Julio</td>
  <td>6</td>
  <td>4</td>
  <td>0</td>
  </tr>
  </tbody>
  </table>
  </div><hr />
  <p><a href="https://www.db-fiddle.com/f/5gmu6EN4UjZDqvyFgb5sSS/0" rel="nofollow noreferrer">View on DB Fiddle</a></p>