Interview Questions--database

Source: Internet
Author: User

1. The difference between the Union and UNION all

is to display the results of multiple slelect statements as a whole.

The difference is that union automatically compresses duplicate results in multiple result sets (the system automatically removes the duplicate tuples), and union ALL displays all results (preserving duplicate Ganso), whether or not duplicates.

Union is inefficient because it is being scanned for duplicate values. If the merge does not intentionally delete duplicate rows, then use UNION ALL

Two SQL statements to be federated, the number of fields must be the same, and the field type is "compatible" (consistent).

2. Paging

With RowNum.

Attention:

Select *  from    (select T.*fromorder by t.id) TableB  whereTableBbetween1andten

The above statement executes the ORDER BY clause after the rownum, so the sorting result is not correct at all.

Adjusted to

Select *  from    (Select A.*from      (Select*from)  orderbydesc) a   wherebetween1  andten

This is the right sort of order, but the SQL statement can be further optimized:

 select  *    ( select  a.*   from  --  (select  *  from   table_name) A  where  ROWNUM   )  where  RN >=  1  

Interview Questions--database

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.