The problem is: There are two tables, one is to record the records of yesterday and the other is to record the records of today.
(1) Newly Added records: There are records today, not yesterday;
(2) reduced records: there are no records today, and there are records yesterday;
To solve this type of problem, you need to use the SQL connection query.
For the sake of simplicity, use table user1 and table user2 to store the records of yesterday and today
CREATE TABLE test4.user1 ( id int NOT NULL, name varchar(20) NOT NULL, PRIMARY KEY (id));
Then update the table to obtain the following results:
The records of yesterday exist in the user1 table:
The records of yesterday exist in the user2 table:
New record:
select test4.user2.id,test4.user2.namefrom test4.user1 right outer join test4.user2on test4.user1.id = test4.user2.idwhere test4.user1.id is null;
Running result:
Reduced records:
select test4.user1.id, test4.user1.namefrom test4.user1 left outer join test4.user2on test4.user1.id = test4.user2.idwhere test4.user2.id is null;
Additional knowledge points:
Inner join, full outer join, left join, right jion
Combination of inner join tables
Full outer is connected to the same combination of two tables. Table A has data that table B does not have (it is displayed as null), and table B has
Table A does not display (null)
Table A left join table B left join, which is based on table A. All data of Table A is combined by table B. Null is not found.
Table A right join table B right join, based on table B, all data of Table B, some combinations of Table. Null is not found.
Http://lhx1026.iteye.com/blog/512776
Http://database.51cto.com/art/201011/234342.htm