PDA

View Full Version : Help combinding 2 mysql queries


rootnik
02-27-2006, 03:20 AM
The first query is the most important one. I'm only using the 2nd query to get a count...

SELECT u.username, u.lastactivity, f.field5, f.field14, f.field15, f.field16, f.field17, f.field19, f.userid
FROM user u
INNER JOIN userfield f
ON u.userid=f.userid
WHERE f.field16 = 'Yes' AND f.field19 > 0
ORDER BY u.lastactivity DESC;

Now I want to get a count of all members who has field19 set as greater than 0. It does not what the value of field16 is in the query below:


$ingame = mysql_result($TheTopQuery, 0, 7);
$custom = $db->query_read("
SELECT field19 FROM userfield
WHERE userfield.field19 = $ingame
ORDER BY userid DESC;
");

Andrew
02-27-2006, 12:26 PM
I think you need to move the variable $ingame from the second query out of the double quotes like so:
$ingame = mysql_result($TheTopQuery, 0, 7);
$custom = $db->query_read("
SELECT field19
FROM userfield
WHERE userfield.field19 = " . $ingame . "
ORDER BY userid DESC
");

rootnik
02-27-2006, 12:49 PM
I think you need to move the variable $ingame from the second query out of the double quotes like so:
$ingame = mysql_result($TheTopQuery, 0, 7);
$custom = $db->query_read("
SELECT field19
FROM userfield
WHERE userfield.field19 = " . $ingame . "
ORDER BY userid DESC
");

Thanks... but somehow the query works as needed without the double quotes.

Both queries work, I am just looking to combind then into 1 query.

Is it even possible considering that the value for $ingame comes from the first query?

Xenon
02-27-2006, 02:47 PM
first of all
the doublequoete are irrelevant in that context

second: i don't really get the sense of the second query, you say you want to count member with the same valuie of field 19, but there is no count function in the query, so?

are you running the second query within a loop or what?
because soley combining a normal and a count query isn't possible, but if you tell us a bit more, maybe an optimization would be possible