in reply to Re: How many Select Querie is considered too much?
in thread How many Select Querie is considered too much?

This set of queries:
SELECT COUNT(*) From Results WHERE user_id = ? AND read = '2' SELECT COUNT(*) From Results WHERE user_id = ? AND read = '3' SELECT COUNT(*) From Results WHERE user_id = ? AND read = '4'
Could be replaced with something like this:
SELECT read, COUNT(*) From Results WHERE user_id = ? AND read in (2,3, +4) GROUP BY read
Assuming there are entries for those three values you would get back 3 rows, where column 0 is the 'read' value, and column 1 is the number that had the value.

UPDATE Fixed the query, as TrekNoid pointed out that I omitted the group by clause. Apparently I neglected to select that portion before hitting copy.

Replies are listed 'Best First'.
Re^3: How many Select Querie is considered too much?
by TrekNoid (Pilgrim) on Aug 10, 2006 at 21:38 UTC
    Wouldn't you need a 'group by' in there?
    SELECT read, COUNT(*) FROM Results WHERE user_id = ? AND read in ('2','3','4') GROUP BY read
    I know Oracle really well, so it's possible that I'm just being Oracle-centric :)

    Trek