if(isset($_POST['Klant'])){
try {
$stmt = $conn->prepare("SELECT (SELECT KltBedrijfsNaam from [tbl relaties] where KltId = auoKltId) as Naam, auoId, auoNaam from dbo.tblAutomatischeOrder where auoNaam in (
select auoNaam from dbo.tblAutomatischeOrder group by auoNaam having count(*) > 1
) and auoStatus= 'LO';");
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="insert_container2">
<h2>Klanten Tabel</h2>
<p>Zoeken op bedrijven!</p>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Zoeken van bedrijven... ">
<table class="w3-table w3-striped w3-bordered w3-border w3-margin-top" id="myTable">
<tr>
<th>Bedrijf </th>
<th>ID van abbo </th>
<th>Abbo naam </th>
</tr>
<?php
foreach ($results as $row) {
echo "<tr>";
echo "<td>".$row['Naam']."</td>";
echo "<td>".$row['auoId']."</td>";
echo "<td>".$row['auoNaam']."</td>";
echo "</tr>";
}
?>
</table>
<?php
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
The convenience does not come, I get all companies that have more than 1 subscriptions. I want the select query indicates precisely whether a company has two single subscriptions
The question is still unclear, why are just those two cases special? I'll take a guess: You want cases where first and third field are equal and that have more than one instance.
mysql> SELECT a, b, c FROM t WHERE (a,c) IN
(SELECT a, c
FROM t
GROUP BY a, c
HAVING COUNT(*) > 1
);
+------+------+------+
| a | b | c |
+------+------+------+
| aa | 1 | qq |
| aa | 2 | qq |
+------+------+------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM t;
+------+------+------+
| a | b | c |
+------+------+------+
| aa | 1 | qq |
| aa | 2 | qq |
| bb | 3 | qq |
| bb | 4 | ww |
| cc | 5 | ee |
| cc | 6 | qq |
+------+------+------+
6 rows in set (0.00 sec)