Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: OT: MySQL combine 2 tables data when Perl 'fails'

by flounder99 (Friar)
on Feb 10, 2004 at 20:13 UTC ( [id://328012]=note: print w/replies, xml ) Need Help??


in reply to OT: MySQL combine 2 tables data when Perl 'fails'

I think you want UNION ALL. This code works on ORACLE, I'm not sure about MySQL.
INSERT INTO c ( SELECT tok, sum(count) FROM ( SELECT tok, count FROM a UNION ALL SELECT tok, count FROM b ) GROUP BY tok )

--

flounder

Replies are listed 'Best First'.
Re: Re: OT: MySQL combine 2 tables data when Perl 'fails'
by tachyon (Chancellor) on Feb 10, 2004 at 21:35 UTC

    Sadly MySQL is not Oracle and has only basic support for sub-selects. It is pretty annoying at times.

    cheers

    tachyon

      Just use a temporary table
      create table d SELECT tok, count FROM a UNION ALL SELECT tok, count FROM b; insert into c select tok, sum(count) as count from d group by tok; drop table d;

      --

      flounder

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://328012]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found