title: OrientDB SQL query to emulate a many to many join
body: <p>Given the following schema created using the OrientDB Document API:</p>
  
  <pre class="lang-java prettyprint-override"><code>    OClass team = getoDocDatabase().getMetadata().getSchema().createClass(TEAM);
      team.createProperty(NAME, OType.STRING);
  
      OClass driver = getoDocDatabase().getMetadata().getSchema().createClass(DRIVER);
      driver.createProperty(NAME, OType.STRING);
  
      OClass car = getoDocDatabase().getMetadata().getSchema().createClass(CAR);
      car.createProperty(NAME, OType.STRING);
  
      // Relationships
      team.createProperty(CARS_HERITAGE, OType.LINKSET, car);
      car.createProperty(BUILT_BY, OType.LINK, team);
      car.createProperty(DRIVEN_BY, OType.LINKSET, driver);
      driver.createProperty(DRIVER_OF, OType.LINKSET, car);
  </code></pre>
  
  <p>What's the sql query to fetch all the teams that Fernando Alonso has driven for?</p>
  
  <p>In relational SQL would be as easy as
  </p>
  
  <pre><code>SELECT team.name FROM {the join} where driver.name = 'Fernando Alonso'
  </code></pre>