MYSQL

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Subqueries in MySQL < 4.1

    1 answers - 325 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi,
    I have a query like this:
    SELECT table1.*,(
    SELECT ****( field2 )
    FRM table2
    WHERE id=10
    ) AS total
    FRM table1
    GRUP 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?
    thanks
  • No.1 | | 855 bytes | |

    Wed, 2006-08-23 at 22:23 +0200, spacemarc wrote:
    Hi,
    I have a query like this:

    SELECT table1.*,(
    SELECT ****( field2 )
    FRM table2
    WHERE id=10
    ) AS total
    FRM table1
    GRUP 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 ****(field2):=@counter FRM table2 WHERE id = 10;

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

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

    Jay

Re: Subqueries in MySQL < 4.1


max 4000 letters.
Your nickname that display:
In order to stop the spam: 3 + 2 =
QUESTION ON "MYSQL"

EMSDN.COM