Reputation: 476
I essentially need to pull out a leadership board if you like of memberID, their first names, last names and their result and order them into highest first.
So far I have the first names and surnames appearing and then results however my query seems to be incorrect as it's showing all possible names, with all possible results as seen below (I know I need a join
, not sure how though and which one):
Below I have actually posted what the results look like within the table:
The info and tables needed below are:
tblMember
holds the fldMemberID
, fldFName
, fldSName
tblMembEntComp
holds the fldResult
.So far I have this, but it's not quite right as you can see on my first screenshot.
<div class="grid-2">
<p><b>LEADERSHIP BOARD</b></p>
<?php
$query = "SELECT `tblMember`.`fldFName`, `tblMember`.`fldSName`, `tblMembEntComp`.`fldResult` FROM `tblMember`, `tblMembEntComp`";
$result = $conn -> query($query);
while($row = $result -> fetch_assoc())
{
echo $row['fldFName']." ".$row['fldSName']." ".$row['fldResult']."<br>";
}
?>
</div>
Upvotes: 0
Views: 45
Reputation: 693
Use for example LEFT JOIN
SELECT T1.*, T2.*
FROM tblMember T1
LEFT JOIN tblMembEntComp T2
ON T1.UniqueCommonField = T2.UniqueCommonField;
Upvotes: 1
Reputation: 781726
You need to specify the columns that relate the two tables:
SELECT m.fldFName, m.fldSName, e.fldResult
FROM tblMember AS m
JOIN tblMembEntComp as e ON m.fldMemberID = e.fldMemberID
Otherwise you get a full cross product between the two tables.
Upvotes: 1