title: How to search for a tuple in a table in mysql
body: <p>I have the following table</p>
  
  <pre><code>CREATE  TABLE IF NOT EXISTS `friends` (
    `userid` INT NOT NULL ,
    `friend` INT NOT NULL ,
    `status` INT(1) NOT NULL ,
    INDEX `user_id_fk_idx` (`userid` ASC) ,
    INDEX `friend_id_fk_idx` (`friend` ASC) ,
    PRIMARY KEY (`userid`, `friend`) ,
    CONSTRAINT `user_id_fk`
      FOREIGN KEY (`userid` )
      REFERENCES `network`.`users` (`userid` )
      ON DELETE CASCADE
      ON UPDATE CASCADE,
    CONSTRAINT `friend_id_fk`
      FOREIGN KEY (`friend` )
      REFERENCES `network`.`users` (`userid` )
      ON DELETE CASCADE
      ON UPDATE CASCADE)
  ENGINE = InnoDB;
  </code></pre>
  
  <p>When I want to insert a new tuple in this table, I want to check if that tuple already exists or not.</p>
  
  <p>Example: when i insert (1,2,0) in table it must run if and only if (1,2,<em>) or (2,1,</em>) is not present in table. Or if i search for tuple (1,2,<em>) in table it must search for (1,2,</em>) and (2,1,*) and give results back.</p>
  
  <p>Currently i am running two queries for this, can this be combined in one query?</p>