How to run multiple queries in mysql without using join keyword?

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.

use a semi-colon after each query

example:

SELECT foo FROM table1
;
SELECT bar FROM table2
;

simple, eh?

:slight_smile:

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.

@SpacePhoenix: Thanks for your advice. But my requirement is something different. I want to test this.


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.

Each row returned by the query has to be fetched. Loop through the result set using a while loop: http://www.php.net/manual/en/function.mysql-fetch-array.php (see example #2).