【发布时间】:2019-06-09 23:52:38
【问题描述】:
我有一张桌子叫contacts:
user_id contact_id
10294 10295
10294 10293
10293 10294
10295 10296
10296 10294
10297 10296
10298 10295
10295 10294
10293 10297
如何从该表中选择user_id 具有contact_id 但感觉没有得到回报的行 - 我的意思是contact_id 没有user_id 作为contact_id?
例如在上述情况下$user_id 是10295。我想要的行是
10295 10296
我可以选择带有user_id 的所有行作为10295 :
$sql = "SELECT * FROM contacts
WHERE user_id = ?";
$stmt2 = $con->prepare($sql) or die(mysqli_error($con));
$stmt2->bind_param('i', $user_id) or die ("MySQLi-stmt binding failed ".$stmt2->error);
$stmt2->execute() or die ("MySQLi-stmt execute failed ".$stmt2->error);
$privateReviews = $stmt2->get_result();
它会给我:
10295 10296
10295 10294
但我正在寻找的只是:10295 10296。
我该怎么做?
【问题讨论】:
-
这个问题的标题非常混乱。
1095在哪里,和/或它与10295 10296有什么关系? -
1095是$user_id,这是从我的应用程序发布的。如果您有更好的标题,请提出建议。这是我能想到的最具体的!像Problem with Select statement这样的东西太笼统了。 -
一哦九五。而不是一哦二九五