Input user defined variables in select statement : <p>I want to store user defined variables in sql select statement and use that variable in sub query like the following:</p>

<pre><code>select user_id, @user_gender:=user_gender 
where user_id in (select user_id from post where post_gender=@user_gender);
</code></pre>

<p>So what I want to do here is I want to store the user_gender value into a variable and use it in a subquery. I know what I am tryinig to do here can be achieved by joins, but what I am posting this example, because I want to know how to actually store value from a row into a user defined variable. </p>

<p>Also, I am having hard time finding good resources that explains how to use user defined variables. Any recommendations?</p>
