Hi, Can someone tell me how to run multiple queries in mysql without using join keyword, and in such manner our database optimization will be done.
I want to fetch more than two columns simultaneously, so that minimum load can be sent to the database server.
I expect Database Gurus will surely provide me the solution for it.
Don’t forget that if you’re using PHP as your server-side language and you’re using the mysql_query() function you won’t be able to run multiple queries in one hit.
Sorry Rudy Sir, I was not able to reply as my PC’s Router was not working. Now its fine.
I have now displayed the example photos, of what type of function I want to do.
I have table structure as displayed in first table.
And want to fetch Both Male and Female Counts in a single query so that request will go only for one time onto the server.
SELECT
gender
, SUM(CASE WHEN age <= 20 THEN 1 ELSE 0 END) AS count1
, SUM(CASE WHEN age > 20 AND
age <= 40 THEN 1 ELSE 0 END) AS count2
FROM tablename
GROUP BY gender
Thanks guido2004, can you please also help me in fetching this data separately in PHP to display in <table></table> as separate record for male and female?
I am getting Array ( [0] => Female [gender] => Female [1] => 0 [count1] => 0 [2] => 2 [count2] => 2 ) after running mysql_fetch_array. Male record is not showing.