1

There are 2 tables. Table a and b. A contains msisdn, firstname, secondname, lastname, regdate(registration data). Table b also has the same fields. I want to compare these two tables, the msisdn's, firstname and lastname fields. If msisdn X in table A has firstname as jim and lastname as halpert, and the same msisdn X has firstname as michael and secondname as scott in table B, i need to get these kinds of msisdn's as my query result. the one's with same msisdn in both tables and different names. if either of these names(first or last) mismatches, that should be shown as result.

I'm sorry if i did not explain the scenario accurately. I hope someone understands and answers this.

thanks :)

Sai Avinash
  • 287
  • 4
  • 7
  • 17

3 Answers3

3
SELECT A.*, B.* 
FROM TABLEA A
INNER JOIN TABLEB B ON A.MSISDN = B.MSIDN
WHERE A.firstname != B.firstname 
OR A.lastname != B.Lastname
JDro04
  • 650
  • 5
  • 15
  • Thank you soo much. this is working perfectly. Also, can you tell me on how to get data of the same msisdn X in these two tables which has the recent regdate? – Sai Avinash Sep 06 '16 at 16:54
  • I don't really understand the question, but I'm sure the solution you're looking for has something to do with `WHERE regdate = (select max(regdate) from table WHERE ...)` – JDro04 Sep 06 '16 at 17:12
  • msisdn X is in table A and table B with two different regdate's. i need to query both the tables and get the result which has the recent regdate. like X regdate in table A is 01/04/2016 and X regdate in table B is 01/08/2016, when i query i should get the result of X from B because that has the most recent regdate – Sai Avinash Sep 06 '16 at 17:22
  • I've got a solution for that, though I'm not sure it is the best one. I'd ask a new question, since this is an entirely separate question. – JDro04 Sep 06 '16 at 17:30
1
Select
    *
From
    Table a
join 
    Table2 b on a.msisdn = b.msisdn
where 
    (a.firstname != b.firstname) OR (a.lastname != b.lastname)
Kidsan
  • 21
  • 1
  • 4
0

If your table is does not have any foreign key you can try this:

SELECT tableA.*, tableB.* 
FROM tableA, tableB
WHERE tableA.col1 != tableB.col1
OR tableA.col2 != tableB.col2

You can change the operator with any operator you want,

Maybe it does not look so pro but it's easier to me :)

kin
  • 33
  • 2
  • 10