SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    In need of an advanced SQL Query

    I have loaded all my Databases into MySQL. I need to query 14 databases simultaneously. I have two two columns that are consistent across all 14, orderID and cartorderID.
    The orderID is the Primary and cartorderId is the Foreign key. There are about 30 to 40 columns per database with other data that I need to ignore. The data extracted needs to be joined into a single row. I may remove the duplicates later with another tool so I'm not concerned with duplicates. At this point the final output table can be called anything because I will be renaming it later in the script.

    Any help offered is greatly appreciated. Thanks in advance.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    sounds like a join might be what you want

    i'm going to assume that when you said "databases" you actually meant "tables"

    now, what's supposed to happen if one of the 14 tables doesn't have a row for a particular orderID?

    having the same orderID number in 14 different tables does sound a little weird, though

    why do you have 14 different tables?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I need to use the JOIN command for those two rows. I did mean "databases". I pulled 14 databases from various hosts all into my local server. I want to query all of them with one SQL command. The two tables are Orders and Cart. I will be pulling data from orderID which is a row in the Order table and cartorderID which is a row in the Cart table.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    and all these hosts all have the same orderID? like, say you had orderID number 937 in one database, it would have to exist in all the other 13 databases before you wanted to see any of the data for 937?

    i hope you don't mind if i say that i still don't believe that you actually want JOIN

    and by the way, when you said orderID is a row, you meant column

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, when I say orderID I mean column. It's just that all the data from the two columns will be merged into one row. So the primary key and foreign key is what ties the two tables together. The rest of all the data in each table is nearly identical.


Tags for this Thread

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
  •