title: Select records from table with inner join and where condition
body: <p>This is the first time I use the JOIN method and I don't get very well.
  I have got this tables(<code>$SupportUserTable</code> and <code>$SupportUserPerDepaTable</code>):</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `razorphyn_support_user_departments` (
  `id`                BIGINT(11)  UNSIGNED    NOT NULL    AUTO_INCREMENT,
  `department_id`     BIGINT(11)  UNSIGNED    NOT NULL,
  `department_name`   VARCHAR(70)             NOT NULL,
  `user_id`           BIGINT(11)  UNSIGNED    NOT NULL,
  `holiday`           ENUM('0','1')           NOT NULL    DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY(`department_name`,`user_id`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
  </code></pre>
  
  <p>and this</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `razorphyn_support_users` (
  `id`                BIGINT(11)  UNSIGNED        NOT NULL AUTO_INCREMENT, 
  `name`              VARCHAR(50)                 NOT NULL,   
  `mail`              VARCHAR(50)                 NOT NULL,   
  `password`          VARCHAR(200)                NOT NULL,
  `reg_key`           VARCHAR(260)                NOT NULL,
  `tmp_password`      VARCHAR(31)                 NULL,
  `ip_address`        VARCHAR(50)                 NOT NULL,
  `status`            ENUM('0','1','2','3','4')   NOT NULL    DEFAULT '3',
  `holiday`           ENUM('0','1')               NOT NULL    DEFAULT '0',
  `mail_alert`        ENUM('no','yes')            NOT NULL    DEFAULT 'yes',
  `assigned_tickets`  INT(5)  UNSIGNED            NOT NULL    DEFAULT 0,
  `solved_tickets`    BIGINT(11)  UNSIGNED        NOT NULL    DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY(`mail`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=55;
  </code></pre>
  
  <p>and this is what I have writtenquery:</p>
  
  <pre><code>SELECT a.id,a.name  
  FROM ".$SupportUserTable." a 
  INNER JOIN ".$SupportUserPerDepaTable." b 
  ON (a.id=b.user_id)  
  WHERE  a.status='2' OR b.department_id=? 
  ORDER BY a.status ASC, a.name ASC
  </code></pre>
  
  <p>Basically I want to retrieve all the id and name from the first table where:</p>
  
  <ul>
  <li>the <code>status</code> in the first table is 2 </li>
  <li>the <code>department_id</code> in the second table is equal to a value, in this case select first table id equal to second table user_id</li>
  </ul>
  
  <p>Reformulated:<br>
  The query must match one of those conditions: </p>
  
  <ul>
  <li>a.status='2'=> retrieve the a.name and a.id </li>
  <li>a.department_id=value => retrieve the a.id and a.name where a.id=b.user_id</li>
  </ul>
  
  <p>But I can't retrieve any record.</p>