How to achieve the intersection of query result sets in MySQL

Source: Internet
Author: User


In MySQL, how does one achieve the intersection of query result sets? Through admission batches, layers, course names, Major, and general subjects, the correspondence between the teaching courses and general subjects is set, you can select multiple majors to correspond to the teaching and examination courses. Www.2cto.com: cascade --- influence level of the admission batch. The entry batch and level affect the Major, the entry batch level, and the name of the affected course. When multiple majors are selected, how does the course name drop-down box show the courses that are shared by multiple majors (if you cannot guarantee that the courses are shared, you may add some courses that are not shared by the major. Solution, the query parameter settings are omitted. Solution 1: temporary table: String queryBasic = "select model from"; StringBuilder queryString = new StringBuilder (); queryString. append (queryBasic); For (int I = 0; I <specialIds. length (); I ++) {queryString. append ("(select model from TeachingPlan_CourseDetail model where model. grade =: grade and model. educationLevel and model. specialId =: specialId) a "); queryString. append (I + ""); if (I <specialId. length ()-1) {queryString. append (", ") ;}} If (specialIds. length> 1) {queryString. append ("where a"); queryString. append (1 + ""); queryString. append (". specialId "if (I <specialId. length ()-1) {queryString. append ("=") ;}} solution 2. Intersection joinString queryBasic = "select model from"; StringBuilder queryString = new StringBuilder (); queryString. append (queryBasic); For (int I = 0; I <specialIds. length (); I ++) {queryString. append ("(select model from TeachingPlan_CourseDe Tail model where model. grade =: grade and model. educationLevel and model. specialId =: specialId) as a "); queryString. append (I + ""); if (I <specialId. length ()-1) {queryString. append ("cross") ;}} If (specialIds. length> 1) {For (int I = 0; I <specialIds. length (); I ++) {queryString. append ("a" + I); queryString. append (". specialId "); if (I <specialId. length ()-1) {queryString. append ("=") ;}} solution 3. subqueries are similar to the preceding one, slightly.

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.