Cancel SQL select 1

Source: Internet
Author: User


Select sum (1) From mytable

If the table contains 100 records, 100 constant 1 is returned.

It is generally used as a condition. When used as a condition:
Select 1 from authors
And
Select * from authors is equivalent

 

Delete from table_a
Where not exists (select 1 from table_ B where table_ B .xh = table_a.xh)
And XH in (select XH from table_a where table_a.lxh = ac_lxh );

Select 1 from ...... Is this method used to check whether there are records in the target table?

 

Exists (select 1 from table_ B where table_ B .xh = table_a.xh)
This is only to check whether table_ B .xh = table_a.xh exists.
Select 1 can also be select 0, select *, select 'A', etc.

Check whether there are any associated records.

Check whether the returned result is true.
It is selected only if it is related.

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.