Php 在另一个查询中使用查询结果
我有一个问题:Php 在另一个查询中使用查询结果,php,sql,Php,Sql,我有一个问题: $sql1="SELECT column1 FROM table_A WHERE username LIKE '".$username."';"; // This may return multiple rows 现在,我需要在另一个查询中使用此查询的结果: $sql2="select all from table_B where mycolumn equals to result we got above" 试试这个: $sql = "select all from ta
$sql1="SELECT column1 FROM table_A WHERE username LIKE '".$username."';";
// This may return multiple rows
现在,我需要在另一个查询中使用此查询的结果:
$sql2="select all from table_B where mycolumn equals to result we got above"
试试这个:
$sql = "select all from table_B where mycolumn in (SELECT column1 FROM table_A WHERE username LIKE'".$username."')";
试试这个:
$sql = "select all from table_B where mycolumn in (SELECT column1 FROM table_A WHERE username LIKE'".$username."')";
使用联接:
$sql = "SELECT
table_B.*
FROM table_A
INNER JOIN table_B ON (table_A.column1 = table_B.mycolumn)
WHERE table_A.username LIKE '".$username."'";
使用联接:
$sql = "SELECT
table_B.*
FROM table_A
INNER JOIN table_B ON (table_A.column1 = table_B.mycolumn)
WHERE table_A.username LIKE '".$username."'";
是什么阻止你这么做?像普通一样从第一个查询中获取结果并在第二个查询中使用?或者只创建一个像“$sql2=select all from table_B其中mycolumn equal select column1 from table_a其中username类似“$username”。;”我的知识很贫乏,一些帮助会很有用吗?是什么阻止你这么做的?像普通一样从第一个查询中获取结果并在第二个查询中使用?或者只创建一个像“$sql2=select all from table_B其中mycolumn equal select column1 from table_a其中username类似“$username”。;”我的知识贫乏,需要一些帮助吗?@user6650650注意SQL注入。@user6650650注意SQL注入。