ORDER BY columns in a UNION
Hi all, I have a pair of statements connected by a UNION, where I need to sort the final result according to columns not appearing in any column list:
SELECT REF(d) FROM DOCUMENT_TABLE d
WHERE d.header$.parentKey = ?
UNION
SELECT REF(d) FROM DOCUMENT_TABLE d, CROSS_TABLE k
WHERE k.doc = d.key$ AND k.folder = ?
ORDER BY d.header$.name
this fails saying that d.header$.name is an invalid identifier (ORA-904), like being out of scope.
Both union branches succeed when run alone (select + order by).
How can I sort by colums without having them to be returned ?
In all examples I found columns are also retrieved and referenced by either alias or by position.
Thanks.
Hi,
In a UNION query, you can only ORDER BY columns in the SELECT clause.
You can do the UNION in a sub-query, then do the ORDER BY in the main query, where you can ORDER BY anything:
WITH union_results AS
SELECT REF (d) AS ref_d
, name
FROM DOCUMENT_TABLE d
WHERE d.header$.parentKey = ?
UNION
SELECT REF (d) AS ref_d
, name
FROM DOCUMENT_TABLE d
, CROSS_TABLE k
WHERE k.doc = d.key$
AND k.folder = ?
SELECT REF_D
FROM union_results
ORDER BY name
;Your front end may be able to hide specified columns, so you could do this without a sub-query.
For example, in SQL*Plus you can say:
COLUMN name NOPRINT
SELECT REF (d) AS ref_d
, name
FROM DOCUMENT_TABLE d
WHERE d.header$.parentKey = ?
UNION
SELECT REF (d) AS ref_d
, name
FROM DOCUMENT_TABLE d
, CROSS_TABLE k
WHERE k.doc = d.key$
AND k.folder = ?
ORDER BY name
;The result set actually contains two columns, but SQL*Plus will only display one.
Similar Messages
-
I am unable to get order by column name in oracle report parameter form
i created query like following in query builder
SELECT CASE_NO, COURT_ID, CASE_TYPE,
INITCAP(PLAINTIFF) PLAINTIFF,INITCAP( DEFENDENT) DEFENDENT,
INITCAP(COUNSEL) COUNSEL, START_DATE, PREVIOUS_HEARING_DATE,
NEXT_HEARING_DATE,INITCAP( DESCRIPTION) DESCRIPTION,
INITCAP(RELIEF) RELIEF,INITCAP(EXTENT) EXTENT,
DECREE_DATE,INITCAP(STATUS) STATUS,INITCAP( LOCATION) LOCATION,
LEGAL_FILE_NO, MSNO
FROM L_CASE_MASTER_MAIN
WHERE to_char(NEXT_HEARING_DATE,'DD-MON-YYYY')=:P_NHD ORDER BY :P_COL
and i created parameter form for these two bind variables :P_NHD,:P_COL
in,:P_COL i wrote lov as Select trim(COLUMN_NAME) from user_tab_columns where table_name='L_CASE_MASTER_MAIN' to get all the columns.
in parameter form i am able to get all the columns but when i am generating report it is not giving results as per my ordered column.
kindly let me know the solution
Report Version :Oracle Reports 11g
Db Version:Oracle 11gHi,
Ordering the column first takes place from the Data Model Itself.
Please Check your column ordering in the report data model. If it is not ordered in a right way then Rearrange it.
Remove your order by in query...
If any issues... let me know
Regards,
Soofi -
Change the order of columns in a report
hi all.
i can't change the order of columns in a report not just by altering the select statement. where can i change it?
thanks.hi master
sir i use 6i report i see full report but i culd not found
report region and report attributes
sir please give me step or idea or tree where report region and report attrinutes"
thanking you
aamir -
In Lion 10.7.5 when viewing files/folders in column view, if I select arrange by name it does not sort the names alphabetically. Is this a bug or is there a way to view files in alphabetical order in column view?
I've been using Column View for years and have it set to None:
It has always shown in alphabetical order automatically. -
How do I change the order of columns in the responses table?
How do i change the order of columns in the responses table in FormsCentral? The default setting puts them in reverse order!
Hi,
The issue with the default ordering of columns in the response table is something that we hope to address in the next update to FormsCentral. In the meantime, you can reorder the columns by selecting them then click/drag using the gray area above the column name. As shown below, an orange marker will show you where the columns will be placed when you release the mouse button.
Sorry for the inconvenience.
Regards,
Brian -
Dynamic ordering ambiguous column issue
I'm working on a stored procedure that will accept a column name from a web application. The stored procedure will use the @SortColumn to sort the results of the query. I'm receiving ambiguous column errors when the column values are passed in
to the query. The original query is written using dynamic sql but I created a simple query to reproduce the issue. Can someone review the sample below and let me know if there is a way to resolve the error.
In the example below, the Over(Order by Emp_ID) section is causing the error. The order by is expecting e.Emp_ID as the order by value. Is there anyway for me to rewrite the logic to allow the correct column alias to be using in the order by statement?
Ultimately, I would like to pass in a paramter for the order by column. Ex. Over(Order by ' + @SortColunm + '
SELECT RowNum
,Emp_ID
,First_Name
,Last_Name
From (Select Distinct ROW_NUMBER() OVER(Order by Emp_ID) as RowNum,
e.Emp_ID as Emp_ID
,e.First_Name as First_Name
,e.Last_Name as Last_Name
FROM Employee e
LEFT OUTER JOIN Team t ON e.team_id = t.team_Id AND e.Emp_id = t.Emp_Id
LEFT OUTER JOIN AccrualType at ON e.Accrual_Type = at.Type
LEFT OUTER JOIN ClosingProcess cp ON e.Emp_id = cp.Emp_ID
where Last_Name like 's%'
) As Employees
order by Emp_IDI've updated my query to use a cte and also included the Row_Number logic. I'm now receiving "Invalid column name 'RowNum". Can anyone explain what I'm doing wrong in the code below? I'm trying to create a stored procedure
that accepts a parameter to handle paging and sorting. The dynamic sql is needed for the SortExpression.
declare @SortExpression varchar(50) = 'Last_Name';
declare @DynSql varchar(max)='';
declare @Emp_ID NVARCHAR(50) = NULL
declare @First_Name VARCHAR(50) = NULL
declare @Last_Name VARCHAR(50) = 's'
declare @StartIndex INT
declare @MaximumRows INT
set @DynSql=
With Employees as
( Select Distinct
e.Emp_ID as Emp_ID
,First_Name
,Last_Name
FROM Employee e
LEFT OUTER JOIN Team t ON e.team_id = t.team_Id AND e.Emp_id = t.Emp_Id
LEFT OUTER JOIN AccrualType at ON e.Accrual_Type = at.Type
LEFT OUTER JOIN ClosingProcess cp ON e.Emp_id = cp.Emp_ID
SELECT ROW_NUMBER() Over (Order By ' + @SortExpression + ') As RowNum,
Emp_ID
,First_Name
,Last_Name
FROM Employees
WHERE RowNum BETWEEN ' + CAST(@StartIndex as varchar(10)) + ' AND ' + '(' + CAST(@StartIndex as varchar(10))+ CAST(@MaximumRows as varchar(10))+ ') - 1 '
If @Emp_ID is not null
Set @DynSql = @DynSql + ' And (Emp_ID = @Emp_ID)'
If @First_Name is not null
Set @DynSql = @DynSql + ' And (First_Name = @First_Name)'
If @Last_Name is not null
Set @DynSql = @DynSql + ' And (Last_Name = @Last_Name)'
exec (@DynSql) -
Is there any performance difference in the order of columns referencing index?
I wish to find out if there is any performance difference or efficiency in specifying those columns referencing index(es) first in the WHERE clause of SQL statements. That is, whether the order of columns referencing the index is important???.
E.g. id is the column that is indexed
SELECT * FROM a where a.id='1' and a.name='John';
SELECT * FROM a where a.name='John' and a.id='1';
Is there any differences in terms of efficiency of the 2 statements??
Please advise. Thanks.There is no difference between the two statements under either the RBO or the CBO.
sql>create table a as select * from all_objects;
Table created.
sql>create index a_index on a(object_id);
Index created.
sql>analyze table a compute statistics;
Table analyzed.
sql>select count(*)
2 from a
3 where object_id = 1
4 and object_name = 'x';
COUNT(*)
0
1 row selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=29)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'A' (Cost=1 Card=1 Bytes=29)
3 2 INDEX (RANGE SCAN) OF 'A_INDEX' (NON-UNIQUE) (Cost=1 Card=1)
sql>select count(*)
2 from a
3 where object_name = 'x'
4 and object_id = 1;
COUNT(*)
0
1 row selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=29)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'A' (Cost=1 Card=1 Bytes=29)
3 2 INDEX (RANGE SCAN) OF 'A_INDEX' (NON-UNIQUE) (Cost=1 Card=1) -
Finder - changing sort order in column view
Anyone know a way to change the sort order when using the COLUMN view in Finder? It's defaulting to alpha and I'd like to change it so when I'm viewing a particular folder the contents are displayed by Date Modified like I can when using the other views.
THANKS!Hi VFRJOEY,
there is no way to change the sort order in column-view. This was under discussion since the very first release of MacOS X but never made it into any one of the releases.
If this answered your question please consider granting some stars: Why reward points? -
Does the order of columns in an index matter?
Hi,
I have a table having composite index, five columns. (col1,col2,col3,col4,col5)
Currently , my index is beginning with the column which having low distinct values and so on.
( in my case the first column have 1 distinct values due to functional behavior ). the second column have 3 distinct values , the third column have many distinct value ( half of the table).
There are many DML queries on this table with different clauses.
Examples:
query 1 : where col1 =val1 and col2 = val2
query 2 : where (col3,col4) in ( select col1,col2 from another_table ) ( for this we can add col1 =val1 and col2 = val2)
My question is : what this best way to create index on this case ?
The order of columns on index depends on its distinct values?
ThanksBIJGA wrote:
Hi,
I have a table having composite index, five columns. (col1,col2,col3,col4,col5)
Currently , my index is beginning with the column which having low distinct values and so on.
( in my case the first column have 1 distinct values due to functional behavior ). the second column have 3 distinct values , the third column have many distinct value ( half of the table).
There are many DML queries on this table with different clauses.
Examples:
query 1 : where col1 =val1 and col2 = val2
query 2 : where (col3,col4) in ( select col1,col2 from another_table ) ( for this we can add col1 =val1 and col2 = val2)
My question is : what this best way to create index on this case ?CREATE INDEX
The order of columns on index depends on its distinct values? yes
Handle: BIJGA
Status Level: Newbie (5)
Registered: Aug 24, 2009
Total Posts: 66
Total Questions: 18 (14 unresolved)
I extend my condolences to you since you rarely get answers to your questions. -
Hi,
in trx MMBE when on-order stock column wiil be again 0 ?
I postes a goods receipt and MIRO but it remains with the quantity of the only one PO I created...
Best regardsHi,
In MMBE Under on stock column will show the open purchase order qty stock. You can cross check with ME2M, enter Material & in selection parameter enter WE101 which shows the open PO of material. Then go to MMBE for same material it will show same qty which shows in open PO. -
IDOC order of columns not same as the data source
Hi,
I am from non SAP background. We are using Informatica to pull data from SAP ECC using the Business Content for Integration by pulling data from IDOCS. Here is my problem:
1) We identified a particular data source (0FI_GL_4) for full mode data pull using Informatica. However, during extraction we found that the order of ports (columns) in the datasource and that generated in the IDOC are not the same. As a result, the loads are failing due to data conversion or mismatch errors.
Question is,how do we ensure that the order of columns in the IDOC generated is the same as that in 0FI_GL_4?
Thanks,
R.Hi,
Please find the below link may useful.
http://wiki.ittoolbox.com/index.php/Re-Connect_R/3_and_BW
Reg,
Venkat -
EA2 - strange column order in "Columns" tab
Hi,
when I click on a table in the left panel, I'd expect the columns in the "Columns" tab appear in the same order as the table has been defined (i.e. ordered by column id). But instead the columns are ordered by primary key. Of course I can doubleclick the column id heading to get the correct order, but when I switch to another table the columns are again sorted by primary key.
If I didn't miss a preference, I'd suggest to change this behaviour to column id sorting by default.Sorry I missed that. Here's the query we use on that:
with pri_cols as ( SELECT cols.column_name column_name, cols.position column_position
FROM all_constraints cons, all_cons_columns cols
WHERE cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
and cols.table_name = :OBJECT_NAME
and cons.owner = :OBJECT_OWNER
ORDER BY cols.table_name, cols.position )
select c.column_name, case when data_type = 'CHAR' then data_type||'('||c.char_length||decode(char_used,'B',' BYTE','C',' CHAR',null)||')'
when data_type = 'VARCHAR' then data_type||'('||c.char_length||decode(char_used,'B',' BYTE','C',' CHAR',null)||')'
when data_type = 'VARCHAR2' then data_type||'('||c.char_length||decode(char_used,'B',' BYTE','C',' CHAR',null)||')'
when data_type = 'NCHAR' then data_type||'('||c.char_length||decode(char_used,'B',' BYTE','C',' CHAR',null)||')'
when data_type = 'NUMBER' then
case when c.data_precision is null then 'NUMBER'
else data_type||'('||c.data_precision||','||c.data_SCALE||')' end
when data_type = 'NVARCHAR' then data_type||'('||c.char_length||decode(char_used,'B',' BYTE','C',' CHAR',null)||')'
when data_type = 'NVARCHAR2' then data_type||'('||c.char_length||decode(char_used,'B',' BYTE','C',' CHAR',null)||')'
else data_type end data_type,
decode(nullable,'Y','Yes','No') nullable,
c.DATA_DEFAULT,column_id, sub.column_position pk,com.comments
from sys.all_tab_Columns c,
sys.all_col_comments com,
pri_cols sub
where c.column_name = sub.column_name(+)
and c.owner = :OBJECT_OWNER
and c.table_name = :OBJECT_NAME
and c.table_name = com.table_name
and c.owner = com.owner
and c.column_name = com.column_name
order by sub.column_position nulls last,column_id
It's supposed to place the pk columns in order followed by the other columns by column_id. -
OM의 ORDER IMPORT시 고려해야 하는 COLUMN들에 대한 설명
제품: MFG_OM
작성날짜 : 2005-11-29
OM의 ORDER IMPORT시 고려해야 하는 COLUMN들에 대한 설명
========================================
PURPOSE
OM의 Order Import시 고려해야 하는 column들에 대해 설명하고자 함.
Explanation
Order Import는 Interface table들과 API set으로 구성되어 있으며,
Order들을 entered, booked 또는 closed status상태로 Import할 수 있다.
1. Order line이 Booked된 상태로 Import되려면,
OE_ACTIONS_IFACE_ALL.OPERATION_CODE column = "BOOK_ORDER"로 적용
2. automatic pricing을 사용하려면,
OE_LINES_INTERFACE.CALCULATE_PRICE_FLAG column을 Calculate Price로
적용
3. 만약, manual pricing을 사용하려면,
OE_LINES_INTERFACE.CALCULATE_PRICE_FLAG column을 Freeze Price로 적용
4. 기존의 Order line을 변경하고자 할 경우,
interface table의 OPERATION_CODE를 "UPDATE'로 적용
5. 기존의 Order line을 cancel하고자 할 경우,
interface table의 OPERATION_CODE를 "UPDATE', ordered quantity = 0
으로 적용
Order전체를 cancel하고자 하는 경우,
Header interface의 OPERATION_CODE를 "UPDATE', CANCEL_FLAG='Y'로 set
6. Internal Order의 경우, Oracle Purchasing은 "Create Internal Sales
Orders" 프로그램을 포함하며, 이는 Internal requisition으로부터 data
를 Order import table로 Load한다.
Example
Reference Documents
Oracle Order Management Suite Implementation Manual, Volumes 1 & 2 Release 11i
Oracle Order Management Users Guide Release 11i
Oracle Order Management Suite API's and Open Interafaces Manual Volume 1, Release 11i
Note 121052.1 -
SQL Query to re-order the columns
Hello All,
I want to know if it is possible to re-order the columns of a table once the rows has been inserted in all the columns.
So for e.g I have initially a table containing 3 columns COL1, COL2 & COL3.
Now after data has been inserted into the table, I want to re-order the columns like COL3, COL2, COl1 or may be COL2, COL1, COL3 etc keeping the data intact.
Cheers,
ParagParag Kalra wrote:
I want to know if it is possible to re-order the columns of a table once the rows has been inserted in all the columns.
So for e.g I have initially a table containing 3 columns COL1, COL2 & COL3.
Now after data has been inserted into the table, I want to re-order the columns like COL3, COL2, COl1 or may be COL2, COL1, COL3 etc keeping the data intact.Why? What is your reason for wanting to do this? What do you want to achieve by it? If we understand the actual problem, then we may be able to provide some usable suggestions.
The reason why your request makes very little sense is that the physical sequence of columns in a row in a datablock, has no impact on you as developer writing code.
Why? Because you control the order in which you want to select columns. You control the order in which you insert columns. You control the order in which you update columns.
SQL allows you the programmer to specify the sequence of columns, and subset of columns, that you want to use in your SQL.
Why would you want to change the physical table definition, and rewrite the entire table on disk (using very expensive I/O) to reorder the physical column sequence? -
Order by column has index which results in full table scan
I have a query on table A which has index for column B.In the query i am using order by column B .In explain plan it shows that the full table scan is performed for table A without picking up the index for B .How can i ensure that index is picked up in the explain plan.Please help its urgent.
PanduPlease help its urgent.Contact Oracle Support in that case.
By making that remark you have just made Blushadow go out to lunch (again) now.... ;)
Depending on your query a full scan could be 100% appropriate here.
But since you didn't post your DB_version, optimizer settings, execution plan etc. there's not much more to say, really, besides:
"Full scans aren't always evil".
See:
[When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=3299435]
[How to post a SQLstatement Tuning Request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
Maybe you are looking for
-
Now my iPhone is non-functional and only shows the chord pointing to the iTunes logo. What do I do? I'm not sure what happened to make it lock or to get the "Recovery" message. Please help...
-
Permission request for going full screen and border alert removal.
Ok so I play some applications games on facebook and currently everytime I go to full screen via the game it requires me to "allow" the program to go full screen. Also there is always a border alert if my cursor touches it and causes an alert to pop
-
hello. my router have some strange problems. after factory defaults setup it work ok, when i change dmz or load configurations, or when i disconnect firewall, after reboot it don't connect to internet at all. at status bar sayed - connected and there
-
I need to update my phone. Do I need to reset the whole phone? If I hit reset will I beable to restore my old information?
-
Where is the promised support for the Mac App Sandbox on OSX?