Reputation: 1635
I have two tables one is Registration which has column as reg_id and first_name and other details and the other table is activity which also has reg_id ,first_name and other details with reg_id as common the tables. There can be multiple entries for 1 reg_id in activity table
I want to have query these two tables in such a way ,I want to know all those reg_id which have different first_name in both the tables.
Eg :if
1st table data
--------------
Reg_id first_name
1 ashu
2 &parker
3 *fzz
4 john
2nd Table data
--------------
Reg_id first_name
1 ashu
2 parker
3 michel
4 john
The output of my query should return 2,3 reg_ids
Upvotes: 0
Views: 1832
Reputation: 11936
Like this......
SELECT t1.reg_id
FROM table1 t1
INNER JOIN table2 t2 ON t1.reg_id = t2.reg_id
WHERE t1.first_name <> t2.first_name
Here is a good link to help you understand SQL Joins : http://www.w3schools.com/sql/sql_join.asp
Upvotes: 1
Reputation: 53
select table1.reg_id from table1
inner join table2 on table1.reg_id = table2.reg_id
where table1.first_name <> table2.first_name
select the one reg id, joing the tables on the reg id value. where the two first name fields don't equal each other
SQL is not case sensitive either.
Upvotes: 2