我有两张桌子。
First tabel called:(data):
----------------------------------------
id link number isik status
----------------------------------------
1 /link 78788 56677 55
Second table called:(test)
----------------------------------------
id kood status
----------------------------------------
1 56677 111
两张桌子中唯一相似的东西是isik和kood
如何从第一个表格中获取isik(First table) = kood(Second table)
所有的行?
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT data * FROM data INNER JOIN test ON data.isik = test.kood";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "Numb: " . $row["number"]. " - Name: " . $row["isik"]. " " . $row["link"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
但我得到0结果
答案 0 :(得分:0)
您可以使用内部联接将表连接在一起,并仅从第一个表中选择行。这将仅选择第二个表具有isik
的匹配值的行。
SELECT `data`.* FROM `data` INNER JOIN `test` ON `data`.`isik` = `test`.`kood`
答案 1 :(得分:0)
SELECT *
FROM First a
WHERE EXISTS (SELECT 1
FROM Second b
WHERE a.isik = b.isik);