SQL minus, Union/static class and global

Source: Internet
Author: User

SQL: minus difference set (set a-Set B) Select int_id from bts_x where int_id in (-1046703870) minus select int_id from bts_x where int_id in (-1046703870,-1422434842) the result is null select int_id from bts_x where int_id in (-1046703870,-1422434842) minus select int_id from bts_x where int_id in (-1046703870) and the result is-1422434842 union, the purpose of the Union all Union command is to combine the results of two SQL statements to view the query results you want. example: Select date from store_information Union Sel ECT date from internet_sales note: In Union usage, the Field Types of the two select statements match, and the number of fields must be the same. In the above example, in the actual software development process, in more complex cases, see the following example select '1' as type, fl_id, fl_code, fl_cname, FLDA. fl_parentid from FLDA where zt_id = 2006030002 Union select '2' as type, xm_id, xm_code, xm_cname, fl_id from xmda where exists (select * from (select fl_id from FLDA where zt_id = 2006030002) A Where xmda. fl_id =. fl_id) order by type, fl_parentid, fl _ The "ID" clause indicates that the two SQL statements are union queries. The query condition is to check whether the fl_id IN THE xmda table matches the fl_id VALUE IN THE FLDA table of the master table, (that is, exist ). union filters out duplicate records after table link. Therefore, after table link, it sorts the generated result sets and deletes duplicate records before returning results. In the query, Union all is encountered. Its usage is the same as union, except that Union contains the distinct function. It removes duplicate records from two tables, but union all does not, therefore, in terms of efficiency, Union all is a little higher, but not much is used in practice. the header uses the first connection block field .......... Union all simply merges the two results and returns them. In this way, if duplicate data exists in the two returned result sets, the returned result sets will contain duplicate data. In terms of efficiency, Union all is much faster than Union. Therefore, if you can confirm that the two results of the merge do not contain duplicate data, use Union all, as shown below: try to use Union all because union needs to be sorted to remove duplicate records, which is less efficient. Select int_id, 4 from bts_x where int_id in (-1046703870) Union select cell_id, 6 from bts_x where int_id in (-1046703870) Results:-1046703870 4 50194 when the field names are inconsistent, union is merged in sequence based on the first one. However, the field types must be consistent, and the number of fields must be consistent. The static class and static class members must have the same static class and non-static class members, but there is a difference: static classes cannot be instantiated. That is to say, you cannot use the new keyword to create a variable of the static class type. Because no instance variable exists, you must use the class name to access the members of the static class. The static constructor is called only once. during the lifetime of the application domain where the program resides, the static class remains in the memory. Static classes are sealed and therefore cannot be inherited. A static class cannot contain constructor, but can still declare a static constructor to assign an initial value or set a static state.

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.