title: SQL LEFT-JOIN on 2 fields for MySQL
body: <p>I have a view <code>A</code> and a view <code>B</code>.</p>
  
  <p>In <code>A</code> I have a lot of information about some systems, like <code>IP</code> and <code>port</code> which I want to preserve all. In <code>B</code> I have just one information that I want to add at <code>A</code>.</p>
  
  <p>The matching fields between the two views are <code>IP</code> and <code>Port</code>. So I have to match those hosts which has the same IP and Port in both views.</p>
  
  <p>Examples:</p>
  
  <h3>View A:</h3>
  
  <pre><code>IP | OS     | Hostname | Port | Protocol
  1  | Win    | hostONE  | 80   | tcp 
  1  | Win    | hostONE  | 443  | tcp 
  1  | Win    | hostONE  | 8080 | tcp 
  2  | Linux  | hostTWO  | 21   | tcp
  2  | Linux  | hostTWO  | 80   | tcp
  3  | Linux  | hostTR   | 22   | tcp
  </code></pre>
  
  <h3>View B:</h3>
  
  <pre><code>IP | Port | State
  1  | 443  | Open
  2  | 80   | Closed
  </code></pre>
  
  <h3>OUTPUT</h3>
  
  <pre><code>IP | OS     | Hostname | Port | Protocol | State
  1  | Win    | hostONE  | 80   | tcp      |
  1  | Win    | hostONE  | 443  | tcp      | Open
  1  | Win    | hostONE  | 8080 | tcp      |
  2  | Linux  | hostTWO  | 21   | tcp      | Closed
  2  | Linux  | hostTWO  | 80   | tcp      |
  3  | Linux  | hostTR   | 22   | tcp      |
  </code></pre>
  
  <p>Note: Is possible that some hosts of the view A has no IP/Port related items in View B.</p>
  
  <p>Is also possible that some hosts of the view A has some match in the View B.</p>
  
  <p>I thought that I should be using LEFT JOIN in order to have all the entry of View A and the correct associated entry of View B, but it didn't work.
  I'm not able to adjust the query with the right WHERE clause and JOIN solution.</p>
  
  <p>Any idea?</p>