Use of oracle order by and union statements when union operations are used, the sorting statement must be placed at the end of the statement. For example: www.2cto.com can only use order by in the last subquery of union, this order by is for the result set after the entire unioning. So: if the names of several subqueries in unoin are different, for example
SQL code select supplier_id, supplier_name from suppliers UNION select company_id, company_name from companies ORDER ?; If the question mark is company_name, "company_name: invalididentifier" is returned when the entire query is executed. (Of course, it is no problem to execute the second subquery containing orderby separately ); this is because the column name of the result set after unioning is the first column name that participates in the union subquery. orderby is for the result set after unioning. For the entire query result, if the field www.2cto.com without the "company_name" is supplier_name, executing the second subquery with order by separately will report "supplier_name: invalididentifier, there is no problem in executing the entire query, because orderby is for the entire result set after unioning, the "entire result set" contains the supplier_name column (the column name of the first union subquery is used as the name of the whole result set after unioning). To avoid such a problem, you can: 1. Replace the actual column name with the column number. For example, SQL code select supplier_id, supplier_name from suppliers UNION select company_id, company_name from companies ORDER BY 2; www.2cto.com 2, or select * from (SELECT SALING_DATE, JOB, name from TABLE1 union select ARRIVE_DATE SALING_DATE, JOB, name from TALBE2) order by SALING_DATE;