user6650650 user6650650 - 3 months ago 7
SQL Question

Using the result of a query in another query

I have a query :

$sql1="SELECT column1 FROM table_A WHERE username LIKE '".$username."';";
// This may return multiple rows


Now, I need to use the result of this query in another one :

$sql2="select all from table_B where mycolumn equals to result we got above"

Answer

Try this:

$sql = "select all from table_B where mycolumn in (SELECT column1 FROM table_A WHERE username LIKE'".$username."')";