Re: Combine SQL query OT

From: Date: Fri, 26 Apr 2002 09:49:27 +0000
Subject: Re: Combine SQL query OT
Groups: php.general 
Request: Send a blank email to php-general+get-94715@lists.php.net to get a copy of this message
Addressed to: Richard Baskett <rick@baskettcase.com> php-general@lists.php.net ** Reply to note from Richard Baskett <rick@baskettcase.com> Fri, 26 Apr 2002 01:47:17 -0700 > > Is there a way I can combine these queries? > > $result = queryDB("SELECT count(ResumeID) FROM Resumes WHERE > typeEmploy='1'"); > $numEmp = mysql_result($result,0); > $result = queryDB("SELECT count(ResumeID) FROM Resumes WHERE > typeContract='1'"); > $numCon = mysql_result($result,0); > $result = queryDB("SELECT count(ResumeID) FROM Resumes WHERE > typeTemp='1'"); > $numTem = mysql_result($result,0); Try: SELECT SUM( IF( typeEmploy = 1, 1, 0 )) AS Employ, SUM( IF( typeContract = 1, 1, 0 )) AS Contract, SUM( IF( typeTemp = 1, 1, 0 )) AS Temp FROM Resumes If type* is always either 1 or 0 you can lose the if: SUM( typeEmploy ) AS Employ ... Rick Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.general (#94715) next »