title: How to display records from one table where condition is from another table?
body: <p>I currently have two table user and user_likes, from this table I want to display all the records from user where the condition is from user_likes table. </p>
  
  <p>For eg. I am jack and my interest is female between the age 20 to 35 and base on this information I want to disply the record who is female between the age 20 to 35.</p>
  
  <p>Heres my table (user):</p>
  
  <pre><code>username(pk)   first_name   last_name   email              date_of_birth(date)    gender
  john123        john         mask        john@gmail.com      1984-12-31            Male
  jack123        jack         cunning     jack@gmail.com      1999-01-23            Female
  pink123        pink         pop         pink@gmail.com      2000-05-01            Female
  </code></pre>
  
  <p>And Heres my other table (user_likes):</p>
  
  <pre><code>username(fk)   gender_likes       age_from    to_age
  john123         Female              18         30     
  jack123         Female              20         35
  pink123         Male                25         35
  </code></pre>
  
  <p>I try this problem using join but I couldn't figure out how to display the exact records I want (eg between 20 to 45): </p>
  
  <pre><code>select * from user inner join user_likes on user_likes.age_from &lt;= DATEDIFF(year, user.date_of_birth, GETDATE()) AND user_likes.to_age &gt;= DATEDIFF(year, user.date_of_birth, GETDATE())
  </code></pre>