title: MySQL trigger that checks data in two tables, then adds into other table
body: <p>I'm trying to right a trigger that will match offers and requests in a database, and if they match add the data into a different table. This is getting pretty complicated for me and maybe someone can point me in the right direction.
  Here's what I have so far:</p>
  
  <pre><code>CREATE TRIGGER rideMatch
  AFTER INSERT ON rideRequest
  FOR EACH ROW
  BEGIN
  IF EXISTS(
      SELECT * from rideOffer r
      where r.time = new.time AND
      r.date = new.date AND
      r.pickUpLocation = new.pickUpLocation AND
      r.dropOffLocation = new.dropOffLocation
      )
   THEN
      INSERT INTO Ride(rideDate, pickUpTime, pickUpLocation, dropOffLocation, driver, carName)
      VALUES(new.date, new.time, new.pickUpLocation, new.dropOffLocation, r.driver, r.carName);
      END IF;
  </code></pre>