title: MySQL select for three fields (like filter)
body: <p>There is a table <code>table</code>:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `table` (
    `main` int(11) NOT NULL,
    `sid` int(11) DEFAULT NULL,
    `rid` int(11) DEFAULT NULL,
    `nid` text
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  
  INSERT INTO `table`(
        `main`, `sid`, `rid`, `nid`
    ) VALUES(
      1, 8, 1, null),
      (1, null, null, "hello"),
      (2, 8, 1, null),
      (2, 1, 2, null),
      (1, 1, 2, null)
  </code></pre>
  
  <p><strong>I need to find field <code>main</code>, where records have next data:</strong> </p>
  
  <pre><code>sid = 8, rid=1, nid = null ;
  sid = null, rid = null, nid = "hello"
  sid=1, rid=2, nid = null
  </code></pre>
  
  <p>Steps for example:</p>
  
  <ol>
  <li>First, we get data: sid = 8, rid=1, nid = null</li>
  <li>With this data we make select-query and result are two records: main =1 and main =2,</li>
  <li>First, we add one condition: sid = null, rid = null, nid = "hello"</li>
  <li>And now query must filter and return one record where main=1</li>
  </ol>