On Wed, 2006-08-23 at 22:23 +0200, spacemarc wrote:
> Hi,
> I have a query like this:
> 
> SELECT table1.*,(
> SELECT COUNT( field2 )
> FROM table2
> WHERE id=10
> ) AS total
> FROM table1
> GROUP BY id
> LIMIT 1
> 
> but the subqueries do not work with mysql < 4.1. How can I convert it
> (or make to work) in MySQL 3.x, 4.0 possibly in one only query?

Your query doesn't show any relationship between the two tables (via a
join condition or correlation) so you would have to do two queries
(which is exactly what your original query does anyway:

SELECT COUNT(field2):[EMAIL PROTECTED] FROM table2 WHERE id = 10;

SELECT table1.*, @counter as total
FROM table1
LIMIT 1;

Note that I took out the GROUP BY clause, which is pointless given the
query's structure of returning the first id column.

Jay


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to