[thelist] [mysql] condensing queries
kris burford
kris at midtempo.net
Tue Nov 4 04:05:25 CST 2003
hiya
i've got a number of mysql queries on a page that i'm thinking i should
condense into one.
firstly, is it a good idea to create a single, but more complex query - or
should i stick to several simple ones?
secondly, if two queries are getting count results from different tables,
if the answer to the above is yes, how would i go about amalgamating them?
for instance:
$sql1 = "select count(image_id) as imagecount from images where user =
'$user' ";
and
$sql2 = "select count(link_id) as link count from links where user = '$user' ";
simply combining them as: $sql = "select count(i.image_id) as imagecount,
count(l.link_id) as linkcount from images i, links l where i.user = '$user'
and l.user = '$user'";
returns the value of images*links, rather than the independent values.
can someone explain what i'm doing wrong?
tia
kris
More information about the thelist
mailing list