Professional Web Applications Themes

Merging databases - PHP Development

Suppose I have a relational database, called "BranchA." I have a second relational database, of identical structure to BranchA, but with different data, and this one is called BranchB. Can I merge the two, into, say, a BranchC somehow on occassion? Thanks, Ike...

  1. #1

    Default Merging databases

    Suppose I have a relational database, called "BranchA."

    I have a second relational database, of identical structure to BranchA, but
    with different data, and this one is called BranchB.

    Can I merge the two, into, say, a BranchC somehow on occassion?

    Thanks, Ike


    Ike Guest

  2. #2

    Default Re: Merging databases

    Ike spilled the following:
    > Suppose I have a relational database, called "BranchA."
    >
    > I have a second relational database, of identical structure to BranchA,
    > but with different data, and this one is called BranchB.
    >
    > Can I merge the two, into, say, a BranchC somehow on occassion?
    This kinda suggests that you didn't normalize your database.

    To answer your question....

    1) do you need to ....
    (
    SELECT 'A' AS Branch, BranchA.* FROM BranchA WHERE $criteria
    ) UNION (
    SELECT 'B' AS Branch, BranchB.* FROM BranchB WHERE $creiteria
    )
    2) if you really have to then...
    DELETE FROM BranchToT;
    INSERT INTO BranchToT SELECT * FROM BranchA WHERE $criteria
    REPLACE INTO BranchToT SELECT * FROM BranchB WHERE $criteria
    I'll leave you to work out why the third statement in the above might work
    better with a REPLACE instead of an INSERT.

    C.

    Colin McKinnon Guest

  3. #3

    Default Re: Merging databases


    "Ike" <rxvhotmail.com> wrote in message
    news:LZzhc.5515$e4.2113newsread2.news.pas.earthli nk.net...
    > Suppose I have a relational database, called "BranchA."
    >
    > I have a second relational database, of identical structure to BranchA,
    but
    > with different data, and this one is called BranchB.
    >
    > Can I merge the two, into, say, a BranchC somehow on occassion?
    Yes, several tables can be merged into a summary table, and you can still
    keep
    BranchA, and BranchB...

    See below or reference (TIP 8) at the following url:
    [url]http://osdn.dl.sourceforge.net/sourceforge/souptonuts/README_mysql.txt[/url]



    CREATE TABLE BranchA (
    pkey int(11) NOT NULL auto_increment,
    a int,
    b varchar(12),
    timeEnter timestamp(14),
    PRIMARY KEY (pkey)
    ) type=MyISAM;

    CREATE TABLE BranchB (
    pkey int(11) NOT NULL auto_increment,
    a int,
    b varchar(12),
    timeEnter timestamp(14),
    PRIMARY KEY (pkey)
    ) type=MyISAM;

    CREATE TABLE BranchSUMMARY_summary (
    pkey int(11) NOT NULL auto_increment,
    a int,
    b varchar(12),
    timeEnter timestamp(14),
    PRIMARY KEY (pkey)
    ) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;


    insert into BranchA (a,b) values (1,'log1');
    insert into BranchB (a,b) values (1,'log2');

    To get combined results

    select * from BranchSUMMARY;


    Hope this helps.

    Regards,

    Mike Chirico


    Mike Chirico Guest

  4. #4

    Default Re: Merging databases

    > CREATE TABLE BranchSUMMARY_summary (

    That's BranchSUMMARY without "_summary" which was a typo on my part.

    CREATE TABLE BranchSUMMARY (
    pkey int(11) NOT NULL auto_increment,
    a int,
    b varchar(12),
    timeEnter timestamp(14),
    PRIMARY KEY (pkey)
    ) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;

    Regards,

    Mike Chirico


    Mike Chirico Guest

  5. #5

    Default Re: Merging databases

    Ok, but, what if certain fields are links to other tables, which you are
    merging as well? How do you know what to add to the fields (assuming these
    keys are integers) -Ike

    "Mike Chirico" <mchiricocomcast.net> wrote in message
    news:QqCdnWtNM_Cwihrd4p2dnAcomcast.com...
    >
    > "Ike" <rxvhotmail.com> wrote in message
    > news:LZzhc.5515$e4.2113newsread2.news.pas.earthli nk.net...
    > > Suppose I have a relational database, called "BranchA."
    > >
    > > I have a second relational database, of identical structure to BranchA,
    > but
    > > with different data, and this one is called BranchB.
    > >
    > > Can I merge the two, into, say, a BranchC somehow on occassion?
    >
    > Yes, several tables can be merged into a summary table, and you can still
    > keep
    > BranchA, and BranchB...
    >
    > See below or reference (TIP 8) at the following url:
    > [url]http://osdn.dl.sourceforge.net/sourceforge/souptonuts/README_mysql.txt[/url]
    >
    >
    >
    > CREATE TABLE BranchA (
    > pkey int(11) NOT NULL auto_increment,
    > a int,
    > b varchar(12),
    > timeEnter timestamp(14),
    > PRIMARY KEY (pkey)
    > ) type=MyISAM;
    >
    > CREATE TABLE BranchB (
    > pkey int(11) NOT NULL auto_increment,
    > a int,
    > b varchar(12),
    > timeEnter timestamp(14),
    > PRIMARY KEY (pkey)
    > ) type=MyISAM;
    >
    > CREATE TABLE BranchSUMMARY_summary (
    > pkey int(11) NOT NULL auto_increment,
    > a int,
    > b varchar(12),
    > timeEnter timestamp(14),
    > PRIMARY KEY (pkey)
    > ) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;
    >
    >
    > insert into BranchA (a,b) values (1,'log1');
    > insert into BranchB (a,b) values (1,'log2');
    >
    > To get combined results
    >
    > select * from BranchSUMMARY;
    >
    >
    > Hope this helps.
    >
    > Regards,
    >
    > Mike Chirico
    >
    >

    Ike Guest

  6. #6

    Default Re: Merging databases

    "Mike Chirico" <mchiricocomcast.net> wrote in message
    news:QqCdnWtNM_Cwihrd4p2dnAcomcast.com...
    >
    > "Ike" <rxvhotmail.com> wrote in message
    > news:LZzhc.5515$e4.2113newsread2.news.pas.earthli nk.net...
    > > Suppose I have a relational database, called "BranchA."
    > >
    > > I have a second relational database, of identical structure to BranchA,
    > but
    > > with different data, and this one is called BranchB.
    > >
    > > Can I merge the two, into, say, a BranchC somehow on occassion?
    >
    > Yes, several tables can be merged into a summary table, and you can still
    > keep
    > BranchA, and BranchB...
    >
    > See below or reference (TIP 8) at the following url:
    > [url]http://osdn.dl.sourceforge.net/sourceforge/souptonuts/README_mysql.txt[/url]
    >
    >
    >
    > CREATE TABLE BranchA (
    > pkey int(11) NOT NULL auto_increment,
    > a int,
    > b varchar(12),
    > timeEnter timestamp(14),
    > PRIMARY KEY (pkey)
    > ) type=MyISAM;
    >
    > CREATE TABLE BranchB (
    > pkey int(11) NOT NULL auto_increment,
    > a int,
    > b varchar(12),
    > timeEnter timestamp(14),
    > PRIMARY KEY (pkey)
    > ) type=MyISAM;
    >
    > CREATE TABLE BranchSUMMARY_summary (
    > pkey int(11) NOT NULL auto_increment,
    > a int,
    > b varchar(12),
    > timeEnter timestamp(14),
    > PRIMARY KEY (pkey)
    > ) type=MERGE UNION(log_01,log_02) INSERT_METHOD=LAST;
    I found this to be quite odd until I looked at your web reference to confirm
    my suspicions:

    CREATE TABLE BranchSUMMARY_summary (
    pkey int(11) NOT NULL auto_increment,
    a int,
    b varchar(12),
    timeEnter timestamp(14),
    PRIMARY KEY (pkey)
    ) type=MERGE UNION(BranchA,BranchB) INSERT_METHOD=LAST;

    The original was will referring to log_x files from your examples at your
    web site.

    - Virgil


    Virgil Green Guest

Similar Threads

  1. merging 2 mp3 files into one
    By BenderB in forum Macromedia Flash Flashcom
    Replies: 1
    Last Post: December 17th, 06:40 AM
  2. Merging PDF
    By Gonzalo_Ferreyra@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 1
    Last Post: September 15th, 03:07 PM
  3. merging cells
    By jplanet59 in forum Macromedia Contribute General Discussion
    Replies: 1
    Last Post: March 14th, 06:42 PM
  4. Merging 2 XML DOM doements
    By Ian P. Christian in forum PHP Development
    Replies: 6
    Last Post: October 17th, 08:04 AM
  5. Federated Databases, joins across databases etc
    By Benjamin Stewart in forum IBM DB2
    Replies: 2
    Last Post: August 1st, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139