Query problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

This is more oriented into the field of SQL, any suggestions?

I am searching for a query that yields what my code below does "in the
sql"

In a "three table join" I am looking for the rows that have the highest
value of "COUNT(we_employee.IDe)", in case two (or more) rows have the
same value - it doesn't matter what row is returned.

/*
email_cp = "email contactperson"
name_first_wee = "first name sales reference"
name_last_wee = "last name sales reference"
IDe = index of table "we_employee" (sales references)
IDc = index of table "company" parent table of "comp_person"
IDp = index of table "comp_person" (contact persons)


$sql = "SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(email_cp, '@', -1), '.',
-2) AS domain, COUNT(we_employee.IDe) AS listed, name_first_wee,
name_last_wee, email_w_wee, IDp, comp_person.IDc FROM ((company INNER
JOIN comp_person ON company.IDc = comp_person.IDc) INNER JOIN
we_employee ON company.IDe = we_employee.IDe) WHERE active = 'Yes' GROUP
BY domain, we_employee.IDe ORDER BY domain, listed DESC";
$res = mysql_query($sql);
while($m = mysql_fetch_array($res)) {
	if ($domain != $m["domain"]) {
		$upd[$m["domain"]] = $m["email_w_wee"];	
	}
	$domain = $m["domain"];
}

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux