title: complex sql query using two tables and regexp
body: <p>I need some help for a complex query. I'm using <strong>autocomplete jquery-ui</strong> for search some users and php+mysql to search.</p>
  
  <p>Users can register with his <code>first_name</code>, <code>last_name</code> and <code>email</code> (requiered fields) on a wordpress/buddypress page.</p>
  
  <p>so, is easy search with regexp on an example that i find on stackoverflow, but i want a make a complex query to search by first_name or last_name or email.</p>
  
  <p><code>first_name</code> and <code>email</code> are in <strong>wp_users</strong> table and <code>last_name</code> is in <strong>wp_bp_xprofile_data</strong> table. i don't want make a custom meta to join names and emails so,</p>
  
  <p>To obtain the <code>first_name</code> and <code>email</code>, the query is:</p>
  
  <pre><code>SELECT * FROM wp_users WHERE display_name REGEXP '^$param' OR user_email REGEXP '^$param'
  </code></pre>
  
  <p>and to obtain de <code>last_name</code>, the query is:</p>
  
  <pre><code>SELECT value FROM wp_bp_xprofile_data WHERE field_id = 5 AND user_id = ".$id."
  </code></pre>
  
  <p>(value is last_name's result and $id=wp_users.ID)</p>
  
  <p><strong>How can a mix this queries?</strong><br>
  if we see this like one table it would be like :<code>selec * from users where first_name=regexp or last_name=regexp or email=regexp</code> (basically), but by the complex structure of wordpress/buddypress i can't do this. please help!!! </p>
  
  <p>eg...3 users, the name of the first user is oscar, the last name of the second user is osbourne, and the email of the third user is omnix.x@gmail.com, if the search starts with 'o', the query will find this 3 users. </p>
  
  <p>PS: i forgot but i need to return the id, first name, last name and email.</p>
  
  <p>Bonus: i'm using the regexp ^$params to find the string at the begin characters. what regexp is better to find this on the everywhere results?</p>