Insert to another table, then compare tables rows

Discussion in 'PHP' started by jigen7, Oct 20, 2009.

  1. #1
    Hi how can compare two rows in two diffrent table and return the columns and his values that are not equal so for example i have table1 and table 2 that has column sum, and vehid , in table1 the sum = 20 and vehid = 1 while in table2 sum=20 and vehid = 2. so the output must return vehid as on those two table are not equal??
     
    jigen7, Oct 20, 2009 IP
  2. DollaradeConner

    DollaradeConner Active Member Affiliate Manager

    Messages:
    200
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Is the sum sort of like an index? Will there be a unique sum for each row on each table, or will there be multiple rows will the same sums?
     
    DollaradeConner, Oct 20, 2009 IP
  3. jigen7

    jigen7 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmm no the sum is not an index.basically i want to compare 2 rows with same columns(number ,name) in 2 different table and return the column where its value didnt match each other?is there any way to do this?
     
    jigen7, Oct 20, 2009 IP
  4. DollaradeConner

    DollaradeConner Active Member Affiliate Manager

    Messages:
    200
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #4
    When you say return the column where its value didn't match, do you just mean the two vehid values? So in the first example, you would just want to return 1 and 2?
     
    DollaradeConner, Oct 20, 2009 IP
  5. jigen7

    jigen7 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yes i would like to get the output vehid then also output the values where they didnt have a match

    ex. vehid table1 value(1)=>table2 value(2) is not equal

    // as for sum will not be returned as they have the same value of 20, thats the gist of it, i really dont know whrere to start
     
    jigen7, Oct 20, 2009 IP
  6. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Hi jigen7,

    I believe it is more of a SQL related query then PHP.

    However, a join query can solve your problem.

    Give a proper example to make it easy for making query.

    Following is the query based on my understanding:

    Select A.sum, B.sum, A.vahid, B.vahid, if(A.vahid = B.vahid, 1, 0) as compare_status from table1 A join table2 B on A.sum = B.sum

    compare_status will be 1 when vahid in both tables are equal, 0 otherwise. I presume that sum is not repeated in any table more than once else this query can give many to many result spoiling the output.
     
    mastermunj, Oct 20, 2009 IP