0

Hi I do have an old table and new table with same index/data. TABLE1 and TABLE2

but TABLE1 has got more data than TABLE2. this was maintained by some one and I dont know how this happened. so my question is how do I compare these two table and find which data is TABLE2 missing?? there is almost 200000 datas there so manually doing is not possible...

4 Answers 4

1

in PHP:

http://us.php.net/manual/en/function.array-diff.php

in SQL:

SELECT * FROM TABLE1 WHERE id {NOT} IN ( SELECT id FROM TABLE2 )

depending on criteria of comparison

0

Solution without nested query:

select TABLE1.id from TABLE1 left join TABLE2 on TABLE1.id = TABLE2.id where TABLE2.id is null
0
0

Did you mean something like this:

SELECT * FROM TABLE1 t1 WHERE NOT EXISTS(SELECT * FROM TABLE2 WHERE t1.id == t2.id)
4
  • can you explain this little bit??
    – mathew
    Jan 10, 2011 at 3:17
  • @mathew: Here I select the tubes in TABLE1 if there's no tube with the same id in TABLE2. I think you should provides more information about 2 tables. In here, I assume that your 2 tables is with the same fields & structure. But it seems (from your comments) that it's not quite right. Jan 10, 2011 at 3:23
  • ok will explain..both tables are same. what I am looking is both table contains user details so I want find which are the users missing in table2
    – mathew
    Jan 10, 2011 at 3:26
  • @mathew: well, now it's more clearer. I think you should update the question for others to see, and please give an example (add some main fields of the table). Jan 10, 2011 at 3:37
0

By same index I am hoping you mean they share a primary key?

SELECT * FROM TABLE1 WHERE username NOT IN (SELECT username FROM TABLE2)

1
  • ok i edited. basially you want to see the rows in TABLE1 for whuich TABLE2 does not have a row with that username, right? Jan 10, 2011 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.