MySQL implements Minus and Intersect)

Source: Internet
Author: User

MySQL implements Minus and Intersect)

MySQL does not implement the Minus and Intersect functions, just as it does not implement the cube function.
 
You can use SQL to implement the same function, which is troublesome.
 
Drop table t1;
 
Drop table t2;

Create table t1 (id int primary key, nickname varchar (20), playNum varchar (20 ));

Create table t2 (id int primary key, nickname varchar (20), playNum varchar (20 ));

Insert into t1 values (1, 1, 10 );

Insert into t1 values (2, 2, 20 );

Insert into t1 values (3, 3, 30 );

Insert into t2 values (1, 1, 10 );

Insert into t2 values (2, 2, 200 );

Insert into t2 values (300 );

Commit;

MySQL implementation Intersection
 
SELECT id, nickname, playNum, COUNT (*)
 
FROM (SELECT id, nickname, playNum

FROM t1

UNION ALL

SELECT id, nickname, playNum

FROM t2

)

Group by id, nickname, playNum

Having count (*)> 1

MySQL implementation difference set
 
SELECT t1.id, t1.nickname, t1.playNum
 
FROM t1 left join t2 ON t1.id = t2.id

WHERE t1.nickname! = T2.nickname

OR t1.playNum! = T2.playNum;

-------------------------------------- Split line --------------------------------------

Install MySQL in Ubuntu 14.04

MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Build a MySQL Master/Slave server in Ubuntu 14.04

Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS

Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.