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