我目前正在运行两个查询以找到一个结果,我有一个很好的感觉,我可以将这两个查询合并为一个。我尝试了下面的方法,但它仍然显示已经从access_number
表中显示的结果。
$query = "select * FROM `$table`.`access_number` WHERE `active`='1'";
$result = mysql_query($query,$db) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
list($dd_inuse) = mysql_fetch_row(mysql_query("SELECT `did` FROM `$table`.`customer_dd` WHERE `did`='$row[did]' AND `callerid`='$callerid' LIMIT 1",$db));
if(!$dd_inuse) {
$goodone = $row['did'];
break;
}
}
我试着这样组合,但没有显示出独特的价值
select `access_number`.`did` from `access_number`
INNER JOIN `customer_dd`
WHERE `customer_dd`.`callerid`='$callerid'
AND `customer_dd`.`did` !=`access_number`.`did` LIMIT 1
底线是,我试图在表
access_number
中找到一个不存在于customer_dd
中的值。我能在这上面得到任何帮助都是非常感谢的!
最佳答案
您可以使用left join
和not null
进行此操作
select
a.access_number from access_number a
left join customer_dd c on c.did = a.did and c.callerid = '$callerid'
where c.did is null
关于php - 将2个Mysql查询合并为一个,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30205655/