查询来自具有相同列但具有不同数据的两个表的数据

时间:2022-03-29 08:30:25

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

我有两个表,一个是注册,其中列为reg_id和first_name以及其他详细信息,另一个表是具有reg_id,first_name和其他详细信息的活动,其中reg_id与表相同。活动表中的1个reg_id可以有多个条目

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.

我希望以这种方式查询这两个表,我想知道所有那些在两个表中都有不同first_name的reg_id。

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

我的查询输出应返回2,3 reg_ids

2 个解决方案

#1


2  

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

选择一个reg id,在reg id值上加入表。其中两个名字字段彼此不相等

SQL is not case sensitive either.

SQL也不区分大小写。

#2


1  

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

这是一个很好的链接,可以帮助您理解SQL连接:http://www.w3schools.com/sql/sql_join.asp

#1


2  

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

选择一个reg id,在reg id值上加入表。其中两个名字字段彼此不相等

SQL is not case sensitive either.

SQL也不区分大小写。

#2


1  

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

这是一个很好的链接,可以帮助您理解SQL连接:http://www.w3schools.com/sql/sql_join.asp