Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've encountered a problem: a query that I can perform on the mysql command-line cannot be performed using DBI. This is the query:
create temporary table foo as select id as id, person as person from mytable in (select id from person)
If I rewrite the query, it works:
create temporary table foo as select mytable.id as id, mytable.person as person from mytable, person where mytable.person=person.id
Although I have found a workaround, I am curious why this would cause problems. The error seems to be in the subquery: "You have an error in your SQL syntax...near 'select id from person)'".

Replies are listed 'Best First'.
Re: DBI (DBD::Mysql) subquery issue
by gam3 (Curate) on Jul 29, 2005 at 12:44 UTC
    I think that there is an error in your syntax
    create temporary table foo as select id as id, 
     person as person from mytable in (select id from person)
    
    should be
    create temporary table foo as select id as id, 
     person as person from mytable where id in (select id from person)
    
    -- gam3
    A picture is worth a thousand words, but takes 200K.
Re: DBI (DBD::Mysql) subquery issue
by davorg (Chancellor) on Jul 29, 2005 at 12:52 UTC

    Which version of MySQL are you using? Subselects were only added in something like version 4.1 - and older versions are still very common.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg