SQL not in

Source: Internet
Author: User

SQL not in: in SQL queries, select * from t1 where c not in (select c2 from t2) If c2 in t2 has null, the result of this statement may be, only when the NULL value must be filtered out in the subquery can www.2cto.com select * from t1 where c not in (select c2 from t2 where c2 is not null) Be normal) the reason for searching is that the SQL-92 standard requires a value of equal to (=) or not equal to (<>) for a null value. When SET ANSI_NULLS is ON, even if column_name has a NULL value, the SELECT statement that uses WHERE column_name = NULL still returns zero rows. Even if column_name has a non-NULL value, the SELECT statement using WHERE column_name <> NULL still returns zero rows. When SET ANSI_NULLS is OFF, equal to (=) and not equal to (<>) Comparison operators do not comply with SQL-92 standards. Use the SELECT statement WHERE column_name = NULL to return the rows with NULL values in column_name. Use the WHERE column_name <> null select statement to return rows with non-NULL values in the column. In addition, use the SELECT statement WHERE column_name <> XYZ_value to return all rows with non-XYZ values and non-NULL values. Exists is also available.

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.