-2

所以我有一个声明:

 $r = mysql_query("Select type from boats where type like '%speed%'");

然后我可以将构造的资源应用于另一个查询吗?

 $r2 = mysql_query("select * from assets where type in ".$r);

我正在尝试做类似的事情

 select * from assets where type in (select type from boats where type like '%speed%')
4

1 回答 1

2

不,你不能这样做。

但是你可以结合sql。

$sql = "Select type from boats where type like '%speed%'";
$r = mysql_query($sql);
$r2 = mysql_query("select * from assets where type in ($sql)");

或者,您可以使用联接来代替子查询。

$r2 = mysql_query("select a.* from assets a 
                   join boats b on a.type = b.type and b.type like '%speed%'");
于 2012-10-17T04:14:17.360 回答