i have this three query i would like to minimize this to one. how would i do it?
$query = "SELECT COUNT(*) FROM states WHERE id = 1";
$query2 = "SELECT COUNT(*) FROM cities WHERE id = 5";
$query3 = "SELECT COUNT(*) FROM areas WHERE id = 3";
also i would appreciate if someone points me to some great website or article that could help me practice and understand MySQL commands. thanks a lot.
EDIT : i would like the script to return the number of rows combined in one result(variable).
Well, the only way (i know) to do this in one query is this:
This hardly can be called an “optimization”, beacuse there are also 3 table scans, but can’t avoid those, since you want to
COUNTon three different tables.EDIT
If you want a sum of three numbers, then this is the answer: