retrieve data from 2 database

Discussion in 'Python' started by crespoh, Jul 28, 2005.

  1. crespoh

    crespoh Guest


    How do I select data from two tables from two different databases and
    compare them? using dbi,odbc
    crespoh, Jul 28, 2005
    1. Advertising

  2. crespoh

    Jason Drew Guest

    Jason Drew, Jul 28, 2005
    1. Advertising

  3. On 27 Jul 2005 20:18:55 -0700, "crespoh" <> declaimed
    the following in comp.lang.python:

    > Hi,
    > How do I select data from two tables from two different databases and
    > compare them? using dbi,odbc

    1) Does "two different databases" mean two different DBMSs, or just
    two logically distinct databases withing one DBMS?

    Some DBMS allow for accessing across "database" boundaries (as
    long as both are maintained within the same DBMS) without using a second
    connection. (MySQL, for example, looks to allow "select ... from
    db_name.table_name..." to cross boundaries.)

    2) Do you mean two tables in /each/ "database" (four tables total)
    or one in each "database"?

    Offhand, if you can do cross-bounds queries, you can probably
    use one query/cursor/connection.

    select d1.t.f1 as d1f1, d1.t.f2 as d1f2, ... d2.t.f1 as d2f1,
    d2.t.f2 as d2f2... from d1.t, d2.t where...

    and then run a test comparing all the d1f* to d2f*

    Otherwise, you may need two cursors to allow for independent

    But maybe you want something like a DIFF report, and the tables
    won't match row for row. For that, you will need to write a DIFF style
    compare loop, and have cursors that can be rewound (or fetchall into
    local data types that you can index).

    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > Home Page: <> <
    > Overflow Page: <> <
    Dennis Lee Bieber, Jul 28, 2005
  4. crespoh

    Steve Holden Guest

    crespoh wrote:
    > Hi,
    > compare them? using dbi,odbc

    Well, a lot depends on the database. If it's two Access .mdb files, for
    example, or two different databases in a single SQL Server instance,
    sometimes you can use SQL statements that cross-refer. Not possible with
    ODBC, though, I fear.

    In that case, we have to hope that the datasets are small enough to hold
    in memory, as Python data structures, and then operate on them as Python
    sets or some such. The DB API delivers the results of queries as lists
    of tuples, each tuple representing a row, but of course they can easily
    be transformed into other Python objects with more convenient properties
    to join the two sets together.

    Much then depends on how you want to join the two sets.

    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC
    Steve Holden, Jul 28, 2005
    1. Advertising

Want to reply to this thread or ask your own question?

Similar Threads
  1. Replies:
  2. Shiva
    Aug 11, 2004
  3. =?Utf-8?B?c2NvdHRybQ==?=

    retrieve binary data from database and display in browser

    =?Utf-8?B?c2NvdHRybQ==?=, Mar 23, 2007, in forum: ASP .Net
    Mar 23, 2007
  4. hib
  5. Roar

    retrieve data from a access database

    Roar, Feb 9, 2004, in forum: ASP General

Share This Page