SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Compare data from two different db tables

    Hey guys..

    I have two database tables. I want to compare fields from tbl_one with fields from tbl_two and the output the resulting similarities.

    So, I want to take table_one.field_one and compare it to table_two.field_one. If they match, I'd want to output something like "CORRECT", and if not "INCORRECT". Or even better might be to simply compare the 10 fields from table one to the corresponding ten fields in table two and then output the number of matching fields.

    Any help?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    sounds like this comparison could be handled completely within SQL

    how to you match rows?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Vancouver, WA
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it have to be done in ColdFusion? If not, take a look http://www.red-gate.com/products/SQL...pare/index.htm (They have a 14-day trial).

  4. #4
    SitePoint Member
    Join Date
    Jul 2005
    Location
    Oklahoma
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could run 2 queries - one for "Table1" and one for "Table2". Then, you could compare the fields returned. Of course, you would have to use some sort of ID so you get a single field value and not the whole column. Then you can just output something based on the results.

    So it would be something like:

    Code:
    <cfquery name="GetTable1" datasource="ds">
        SELECT field_one
        FROM table1
        Where id = theidyouwant
    </cfquery>
    
    <cfquery name="GetTable2" datasource="ds">
        SELECT field_one
        FROM table2
        Where id = theidyouwant
    </cfquery>
    
    <cfif GetTable1.field_one eq GetTable2.field_one>
    Correct!
    <cfelse>
    Incorrect :(
    </cfif>


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
  •