I need some help figuring out how to go about getting the results I need from a query. I know there is an easy solution but I can't seem to find it either in the PHP manual or in a search here.
My example database :
id name email status
------------------------------------------------------
1 Bob bob@email.com 1
2 Richard rich@email.com 1
3 Richard rich@email.com 0
4 Bob bob@email.com 1
5 Bob bob@email.com 0
6 Mark mark@email.com 1
7 Mark mark@email.com 1
8 Bob bob@email.com 1
9 Steve steve@email.com 0
The query I'm using to extract data :
$sql = "SELECT * FROM table WHERE status = '1' ORDER BY id";
$result = @mysql_query($sql, $connect) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$name = $row['name'];
}
echo "$name";
This query yeilds the following result :
Bob
Bob
Bob
Richard
Mark
Mark
What I need to do is to just get a result that displays the name of the person with the most records in the database who have a status of 1 (in this case, Bob) ONLY... and only once. Would a "LIMIT 1" work in this case?
I'm sure this is a simple solution, but again I've not located anything that suggests a fix.