Sub query generating errors in MySQL only

Hi there,

I have this query below and the SELECT COUNT statements are generating
errors in MySQL with php and I have no clue why. I would like to be
able to do this because this also works for other DB's. Any ideas?

Kind regards, Seansan

SELECT ttrss_feeds.*,
SUBSTRING(last_updated,1,19) AS last_updated_noms,
(SELECT COUNT(ttrss_entries.id) FROM ttrss_entries,
ttrss_user_entries
WHERE ttrss_user_entries.feed_id = ttrss_feeds.id AND
ttrss_user_entries.ref_id = ttrss_entries.id AND
owner_uid = 'admin') AS total,
(SELECT COUNT(ttrss_feeds.id) FROM ttrss_entries,ttrss_user_entries
WHERE feed_id = ttrss_feeds.id AND unread = 'true'
AND ttrss_user_entries.ref_id = ttrss_entries.id
AND owner_uid = 'admin') as unread,
cat_id,
last_error,
ttrss_feed_categories.title AS category,
ttrss_feed_categories.collapsed
FROM ttrss_feeds
LEFT JOIN ttrss_feed_categories ON (ttrss_feed_categories.id =
cat_id)
WHERE ttrss_feeds.owner_uid = 'admin' AND parent_feed IS NULL
Seansan [ So, 13 August 2006 13:35 ] [ ID #1428771 ]

Re: Sub query generating errors in MySQL only

Seansan wrote:

> I have this query below and the SELECT COUNT statements are generating
> errors in MySQL with php and I have no clue why. I would like to be
> able to do this because this also works for other DB's. Any ideas?

Without even looking at the query, I would guess you have MySQL 4.0 or older
version, which don't support subqueries, what you need to do is to upgrade
your MySQL to a later version, 5.0 which should be the current stable one.

For more info about subquery errors, check this page at mysql.com:
http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html



//Aho
Shion [ So, 13 August 2006 13:39 ] [ ID #1428772 ]

Re: Sub query generating errors in MySQL only

J.O. Aho wrote:
> Seansan wrote:
>
> > I have this query below and the SELECT COUNT statements are generating
> > errors in MySQL with php and I have no clue why. I would like to be
> > able to do this because this also works for other DB's. Any ideas?
>
> Without even looking at the query, I would guess you have MySQL 4.0 or older
> version, which don't support subqueries, what you need to do is to upgrade
> your MySQL to a later version, 5.0 which should be the current stable one.
>
> For more info about subquery errors, check this page at mysql.com:
> http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html
>
>
>
> //Aho

Thanks for your answer. I have version MySQL 3.23.58, this is probably
it. Anybody any hints on how to fix this for lower versions?
Seansan [ So, 13 August 2006 17:15 ] [ ID #1428774 ]

Re: Sub query generating errors in MySQL only

Seansan wrote:

> Thanks for your answer. I have version MySQL 3.23.58, this is probably
> it. Anybody any hints on how to fix this for lower versions?

You need to make two extra queries and fetch the "total" and "unread"
separately from the main select and then in php merge the three selects to
your result array (in case you do save thing in a such).

If this won't be an option for you, then you need to upgrade to MySQL 4.1.


//Aho
Shion [ So, 13 August 2006 17:55 ] [ ID #1428776 ]

Re: Sub query generating errors in MySQL only

Upgrade, get with the time bro!
"J.O. Aho" <user [at] example.net> wrote in message
news:4k90c1Fb2qpdU1 [at] individual.net...
> Seansan wrote:
>
>> Thanks for your answer. I have version MySQL 3.23.58, this is probably
>> it. Anybody any hints on how to fix this for lower versions?
>
> You need to make two extra queries and fetch the "total" and "unread"
> separately from the main select and then in php merge the three selects to
> your result array (in case you do save thing in a such).
>
> If this won't be an option for you, then you need to upgrade to MySQL 4.1.
>
>
> //Aho
Webwasp [ Mo, 14 August 2006 01:25 ] [ ID #1429841 ]
PHP » alt.php.sql » Sub query generating errors in MySQL only

Vorheriges Thema: LAMP and PHP EVANGALISTS NEEDED IN SEATTLE!!!!
Nächstes Thema: Delete Script