Get the App
SLTechnology News&Howtos  ›  Database  › 

How to find intersection in mysql

Shulou Source: shulou.com Published: 2022-05-31 11:47:18 10月03日 Update

Mysql how to seek intersection, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

In mysql, you can use the "SELECT" statement and the "INNER JOIN" keyword to query the intersection and find the intersection data. The syntax "SELECT field name FROM data Table 1 INNER JOIN data Table 2 USING (field name)".

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Create two tables

CREATE TABLE `object_ a` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `oname` varchar (50) DEFAULT NULL, `otim` varchar (50) DEFAULT NULL, `create_ time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1

Add data

CREATE TABLE `object_ b` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `oname` varchar (50) DEFAULT NULL, `ofu` varchar (50) DEFAULT NULL, `create_ time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1

Add data

Query intersection

SELECT a.oname,a.odesc FROM object_a an INNER JOIN object_b b ON a.oname=b.oname AND a.odesc=b.odesc

Equivalent to

SELECT a.oname.odesc FROM object_a an INNER JOIN object_b b USING (oname,odesc)

The results are as follows

PS: other databases can try this method.

After reading the above, SELECT oname,odesc FROM object_a INTERSECTSELECT oname,odesc FROM object_b, have you mastered how to find the intersection of mysql? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Data intersection content fields data tables methods more questions queries helpless for this two keys keywords writing reasons for this skills tutorials databases Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS Apple NVidia vpn