Order by column not in select statement
Want to select multiple columns from a single table, and order by a column on the same table, but that is not in the select statement, or simply not shown in the output of the statement..
Any help appreciated..
Hi,
In most cases, you can ORDER BY any column in the table(s) used, whether it is in the result set or not.
Otherwise, include the column. Your front-end tool may be able to suppress the display, if you really don't want to see it.
For example, in SQL*Plus
COLUMN dont_show NOPRINTcauses any column named (or aliased) dont_show not to appear in the output.
In Oracle9 (and up) sub-queries with ORDER BY return their results in order, so you can say things like:
SELECT col_a
, col_b
FROM (
SELECT col_a
, col_b
, col_x -- Not included in final output
ORDER BY col_x
);
Similar Messages
-
How to display number of rows as columns in a select statement? This is on
How to display number of rows as columns in a select statement? This is on 10g R2.
Thanks,
RFor the current (ie. row 1 of 100)
row_number over (order by -pick_a_column_set) as rnfor the total number of columns returned in your query
count(*) over() as total_count -
Using ORDER BY for column that's not in SELECT statement of select list?
Hi all.
I have a select list on an APEX page at apex.oracle.com, and I would like to order this by the value of column UnitOrder.
The SQL is as follows:
SELECT DISTINCT foodunit.name AS display_value, foodunit.foodunitid AS return_value
FROM foodunit, food
WHERE foodunit.foodid = :P18_FOODID
ORDER BY foodunit.unitorder ASC;Off course, this code won't work. And since it's a select list, I can't just add foodunit.unitorder to the SELECT statement. Also, I can't get rid of the DISTINCT, because then for some reason it tends to display an infinite amount of the same row...
The point of ordering it by UnitOrder is that all units who begin with gram, ml, mg, kg,... etc, will be shown on top of the select list. All other food units will be shown on the second place and so on.
The column UnitOrder holds either 1 or 2 as a value. 1 is the value for all rows that should be displayed at the top of the select list, 2 is the value for all the rest.
So, what I want is that all rows in which the UnitOrder is 1, get displayed on top of the select list. Usually only 2 list items get shown in the select list at a time, depening on which food item a user has selected. The select list then refines to certain rows that match the foodid etc etc..
If anyone has an idea, I'd be very happy to hear about it.Thanks! I didn't think about using a join. Code works now, and is as follows:
SELECT foodunit.name AS display_value, foodunit.foodunitid AS return_value
FROM foodunit
INNER JOIN food
ON food.foodid = foodunit.foodid
WHERE foodunit.foodid = :P18_FOODID
ORDER BY foodunit.unitorder ASC; -
Toplink Essentials creates not usable select statement
My problem is the following:
I have the following NamedQuery statement in an JPA Entity Class:
@NamedQuery(name = "Leasingteilvertrag.findSearch",
query = "select distinct o " +
" from Leasingteilvertrag o " +
" left outer join o.sachbearbeiterList s " +
" where (:wtvStatusBearb1 is null or :wtvStatusBearb2 = -1 or o.wtvStatusBearb =
:wtvStatusBearb3)" +
" and (:wtvStatusVerwert1 is null or :wtvStatusVerwert2 = -1 or o.wtvStatusVerwert = :wtvStatusVerwert3)" +
" and (:wtvAdressNr1 is null or :wtvAdressNr2 = -1 or o.wtvAdressNr =
:wtvAdressNr3)" +
" and (:wtvEingangsdatum1 is null or o.wtvEingangsdatum >= :wtvEingangsdatum2)" +
" and (:wtvEingangsdatumBis1 is null or o.wtvEingangsdatum <= :wtvEingangsdatumBis2)"
+
" and (:wtvLlvNr1 is null or o.wtvLlvNr = :wtvLlvNr2)" +
" and (:wtvFirma1 is null or o.wtvFirma = :wtvFirma2)" +
" and (:wsbId1 is null or :wsbId2 = -1 or s.wsbSbId = :wsbId3)")
Oracle Toplink translates this (according to to opmn log of the Application Server)
to:
SELECT DISTINCT t0.WTV_ID, t0.WTV_SL_PLUS_KNZ, t0.WTV_ABGESCHLOSSENDATUM, t0.WTV_SL_TECHNIK_DATE, t0.WTV_ADRESS_POOL, t0.WTV_SL_TECHNIK_KNZ,
t0.WTV_AKTENZEICHEN_RA, t0.WTV_SONDERAFA_OBJEKTE_AKTUELL,
t0.WTV_ANZAHLRUECKSTAENDIGERRATEN, t0.WTV_SONDERAFA_OBJEKTE_GEBUCHT,
t0.WTV_BANKAUSKUNFT_KNZ, t0.WTV_STATUS_BEARB, t0.WTV_EINGANGSDATUM,
t0.WTV_STATUS_BEARB_DATUM, t0.WTV_EINSCHAETZUNG_BONI, t0.WTV_STATUS_VERWERT,
t0.WTV_EWB_DATUM_ERFASSUNG, t0.WTV_STATUS_VERWERT_DATUM, t0.WTV_EWB_GEBUCHT,
t0.WTV_STATUS_FREIGABE, t0.WTV_EWB_SB_ERFASSUNG, t0.WTV_STATUS_FREIGABE_DATUM,
t0.WTV_FIRMA, t0.WTV_VERBLEIB_AKTE, t0.WTV_WAEHRUNG_AUSFALL,
t0.WTV_KUENDIGUNGSFORDERUNG, t0.WTV_WAEHRUNG_EWB, t0.WTV_LLV_NR,
t0.WTV_WAEHRUNG_RUECKST_ANR, t0.WTV_LTV_NR, t0.WTV_WAEHRUNG_SONDERAFA_OBJEKTE,
t0.WTV_PROZESSKOSTEN_RISIKO, t0.WTV_WAE_EINSCHAETZUNG_BONI,
t0.WTV_RUECKST_ANRECHNUNG_GEBUCHT, t0.WTV_WAE_KUENDIGUNGSFORDERUNG,
t0.WTV_SL_KASKO_DATE, t0.WTV_WIEDERGESUNDUNGSDATUM, t0.WTV_SL_PLUS_DATE,
t0.WTV_ABGESCHLOSSEN_KNZ, t0.WTV_AKTENZEICHEN_FAV, t0.WTV_TEILRISIKO_KNZ,
t0.WTV_AUSFALL, t0.WTV_BETRUG_KNZ, t0.WTV_EINGANGSDATUM_ALT,
t0.WTV_CHANGE_USER, t0.WTV_EWB_DATUM_FREIGABE, t0.WTV_CHANGE_DATE,
t0.WTV_EWB_SB_FREIGABE, t0.WTV_FREIGABE_KOMMENTAR, t0.WTV_KUENDIGUNGSDATUM,
t0.WTV_ADRESS_NR, t0.WTV_ALTFALL_KNZ, t0.WTV_OPERATIONELLES_RISIKO,
t0.WTV_BEMERKUNG, t0.WTV_SACHSTAND, t0.WTV_EWB_AKTUELL,
t0.WTV_LLV_NR_UMFINANZIERUNG, t0.WTV_EWB_KORREKTUR, t0.WTV_SL_KASKO_KNZ,
t0.WTV_FIRMA_UMFINANZIERUNG, t0.WTV_RUECKST_ANRECHNUNG_AKTUELL,
t0.WTV_KUENDIGUNGSFORDERUNG_ALT, t0.WTV_LEASINGVERTRAG_ID,
t0.WTV_RUECKST_ANRECHNUNG_BUC_ID, t0.WTV_EWB_BUC_ID,
t0.WTV_SONDERAFA_OBJEKTE_BUC_ID FROM VWDB_LEASINGTEILVERTRAG t0,
VWDB_LEASINGTEILVERTRAG t2, VWDB_SACHBEARBEITER t1 WHERE (((((((((((? IS NULL)
OR (? = (? - ?))) OR (t0.WTV_STATUS_BEARB = ?)) AND (((? IS NULL) OR (? = (? -
?))) OR (t0.WTV_STATUS_VERWERT = ?))) AND (((? IS NULL) OR (? = (? - ?))) OR
(t0.WTV_ADRESS_NR = ?))) AND ((? IS NULL) OR (t0.WTV_EINGANGSDATUM > ?))) AND
((? IS NULL) OR (t0.WTV_EINGANGSDATUM < ?))) AND ((? IS NULL) OR (t0.WTV_LLV_NR
= ?))) AND ((? IS NULL) OR (t0.WTV_FIRMA = ?))) AND (((? IS NULL) OR (? = (? -
?))) OR (t1.WSB_SB_ID = ?))) AND (t1.WSB_LTV_ID (+) = t0.WTV_ID))
The Problem is the "VWDB_LEASINGTEILVERTRAG t2" entry in the FROM clause of the generated select statement. This causes the select to generate the cartesian product.
Has anyone had such a problem before? How can this be solved?Hello,
I have exactly the same problem (with a simpler query though). I'm running my webapp on a GlassFish V2 (build b09d-fcs), Toplink Essentials JPA impl. and a MySQL 6.0.4 database server.
I'm trying to run the following JPQL query: select f from Foo f where (1=1) and f.title = :title
After having set persistence log levels to FINE, the following SQL is displayed:
select t0.XXX, t0.YYY from Foo t0, Foo t1 where ((?=?) and (t0.title= ?))
bind => [1, 1, Bar]
(1 = 1) is used because of dynamic query generation (application code)
The problem is that the additional from clause is generating a cartesian product on my Foo table, which causes many duplicated results to be returned.
I have simplified the select part of the query but the actual query is of the same kind: no join, only 1 entity, no inheritance, a single N:1 lazy-initialized entity (*Foo-1FooParent). The only "exotic" facet of my Foo mapping is the use of an @Enumerated column.
Is it the expected behavior?
-Titix -
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 -
GR of Process order - Document does not contain selectable items
Hi Guru's,
While doing GR for process order, user is not able to do the GR because of the below message:
Document XXXXXX does not contain selectable items
The other user is able to do the GR. The status of process order is
REL PCNF PRC EXPL EXTS GMPS MANC PDLV. There is overdelivery tolerance so, the delivered quantity is more than ordered qty.
There is no auto GR setting, no COGI errors, no final delivery indicator, no authorisation issue.
What could be the reason for this ?
Thanks in advance.
Regards
KalyanHi Dee Joy,
I am using MIGO for posting the GR. So, kinldy let me know what setting in MIGO needs to be done.
Regards
Kalyan -
Creating a record group not via select statement
Normally a record group is created via a select statement
(f.e. Querystr='Select deptno,dname from dept
populate_group_with_query( GroupId, QueryStr )
Is it possible to create it via a package procedure sending a
refcursor / arrayFIND_GROUP(groupname);
CREATE_GROUP_FROM_QUERY(groupname, qry);
POPULATE_GROUP_WITH_QUERY(rgid, qry);
Add_Group_Column(...);
Add_Group_Row(...); -
How do I group by only one column in a SELECT statement?
Hi everyone,
Here is my novice question:
I would like to run a query where I select (display) several columns from my table, yet group (categorize) by one of these columns.
For example:
SELECT A, B, COUNT(A)
FROM TableX
GROUP BY A
I realize now that this is not valid. My first question is why? Doesn't it make sense that you would want to group by only one of the columns? To me, it seems natural that you would most often want to categorize by one attribute, which is why it seems odd that this is not valid. I realize that I can remove column B, but I do want to display that info. I could also change the last statement to GROUP BY A, B to avoid errors, but this will also not display what I am looking for.
In addition to understanding why Oracle is set up this way, I guess I also need to know how I can legally accomplish this query, grouping by A but also displaying the values of B.
Thank you very much for your help!
HollyHi everyone,
Thank you for your responses... very interesting and useful. Since I came across inline views in my reading, I tried the approach recommended by g feng, although I am eager to try the other approaches too.
I ended up using an inner join simply to get more descriptive info. on the column that was being counted. With Y representing this second table, Y.B being the column containing the descriptive info., and A being the common key between X and Y, here is the simple code I came up with.
SELECT Y.B, V.*
FROM Y,
SELECT A AV, COUNT (*)
FROM X
GROUP BY A
) V
WHERE V.AV = Y.A
Does this seem correct... anything I need to watch out for?
Thanks again to everyone for your help!!
Holly -
Cannot use alias for dynamic column name in SELECT statement
Hi,
I want to retrieve values from several tables by using dynamic column & table name as below:
DATA: tbl_name(30) TYPE c VALUE '/bic/tbi_srcsys', " staticly initialized for this example
col_name(30) TYPE c VALUE '/bic/bi_srcsys'. " staticly initialized for this example
SELECT (col_name) INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).
The internal table "it_values" does not contain a field named "/bic/bi_srcsys", instead it has another generic field "value" so that the above code can be applied to other tables. I tried to use alias (AS) as below:
SELECT (col_name) AS value INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).
But this cannot work. I know that there are other ways to solve this problem, such as by using a single field in SELECT .. ENDSELECT and subsequently appending it to the work area and internal table as below:
SELECT (col_name) INTO (lv_value) FROM (tbl_name).
wa_value-value = lv_value.
APPEND wa_value TO it_values.
ENDSELECT.
Just wonder if there is any other more elegant workaround, because I might have several other fields instead of only one?
Thanks.
Regards,
Joon MengHi Suhas,
thanks for the quick reply.
Sorry that I have not well described the structure of the internal table "it_values". This internal table contains several other fields (key, type, value, etc.).
I guess that the following code
SELECT (col_name) INTO TABLE it_values FROM (tbl_name).
works if the internal table only has one field (value) or the field "value" is in the first position, right?
In this case, I need to fill the "value" field of internal table it_values (ignore the other fields like type, key) with values retrieved from (col_name) of the DDIC table.
Looking forward to your reply.
BR,
Joon Meng -
Problems with varchar2 column and a select statement
Hi to all,
I am new to ODP...so I would really appreciate your help..
I am having problems with using the following code:
con.ConnectionString = "User Id=bla;Password=bla;Data Source=bla;";
string cmdQuery = "SELECT * from try where data ="+textBox1.Text+"";
OracleCommand cmd = new OracleCommand(cmdQuery);
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
OracleDataReader reader = cmd.ExecuteReader();
while (reader.Read())
MessageBox.Show(reader.GetString(0)+"");
cmd.Dispose();
con.Close();
where:
data is the name of a field in the table
textBox1 is the name of a text box where the user inserts the values..
The error that appears is "Invalid identifier"..
I hope it makes sense...and please help...Hi,
I'm fairly sure it IS the single quotes actually. Print out the string you're trying to excute, then try it outside odp.net, does it work?
For example:
SQL> select * from dual where dummy=foo;
select * from dual where dummy=foo
ERROR at line 1:
ORA-00904: "FOO": invalid identifier
SQL> select * from dual where dummy='foo';
no rows selected
Cheers,
Greg -
Order of records in o/p of select statement
Hi all
I have doubt regarding the select statement. I need to execute a select statement (with out any order ie with out "order by") which searchs a table. I want to know whether in any
circumstances the order of the records of the select statement is different.
sample select statement which I need to execute
select emp_no from emplyees where designation = 'programer'
in one word order of records of in the o/p of a select statement will be unique ?
(provided same query same, table,)
can u plz quote the link to get more information
regards
RenjithHi,
YES, you can
Do Order By Without Using Order By Clause
in your select statement.
I assume that you have unique data ( e.g. emp_no in Emp Table ) and you you do not want to use Order by clause.
Solution 1:
Select Emp_no
from Emp
group by Emp_no;
the o/p will be in the sorted in the Ascending order.
Solution 2: ( Only for columns holding Numeric Values )
Select Emp_No
From Emp
Where 99999 - Emp_no in ( Select 99999 - Emp_no from Emp );
Again this will sort the result will be in the Descending Order. you can use any big number instead of 99999 but it should be greater than Emp_no value.
Note: You Should only use this method on not very large tables coz of performance issue.
Hope this will solve your problem.
Any Comment on this, any body.
Thanks and Regards
There is always a solution to the problem, And if there is no solution of a problem then problem is not a problem. -
Retrieving multiple values from one column in SELECT statement
Hi,
I have a slight dilemma in that I'm trying to pull down all the values from a column from a select statement that includes some JOINS in it.
If I run the query at the SQL Plus prompt, it pulls back all the values/rows.
When I run the select (and prepared ) statement in my JSP, it only pulls back one of the 4 values I'm trying to retrieve.
e.g.
at the DB level :
SELECT role_name, CC_ID FROM votetbl a
INNER JOIN APPROVERS b ON
a.BUSVP = b.BUSVP AND
a.BRANCH = b.BRANCH
WHERE CC_ID = 1688this will return:
ROLE_NAME CC_ID
ops 1688
ops 1688
comply 1688
legal 1688
comply 1688
When run in my JSP, like so:
String primID3a = request.getParameter("primID");
Statement stmtovoter = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
String prepvotSQL = "SELECT role_name, CC_ID FROM votetbl a INNER JOIN APPROVERS b ON a.BUSVP = b.BUSVP AND " +
"a.BRANCH = b.BRANCH WHERE CC_ID = ?";
PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
prepvotstmt.setString(1, primID3a);
ResultSet rest3 = prepvotstmt.executeQuery();
rest3.next();
String votecat = rest3.getString(1);
out.println("Vote category: "+votecat);I only get ops returned.
Do I need to run an enumerator? Or reqest.getParameterValues or use a while statement around the results set?
Any feedback and direction here is welcomed!
Thanks!Actually, I tried looping and still only get 1, but returned several times.
i.e.
PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
prepvotstmt.setString(1, primID3a);
ResultSet rest3 = prepvotstmt.executeQuery();
rest3.next();
String votecat = rest3.getString(1);
while (rest3.next()) {
out.print("category roles "+votecat);
}then I get returned the following:
admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admin
like so.
Where as at the DB level I get
ROLE_NAME CC_ID
admin 1688
ops 1688
ops 1688
ops 1688
ops 1688
ops 1688
ops 1688
ops 1688
risk 1688
comply 1688
legal 1688
legal 1688
ops 1688
comply 1688
Maybe the while should go around the getString(1) designation? But I was thinking I'd tried that and gotten invalid cursor error
Something is definitely amiss, between the prepared statement in the servlet and the SELECT statement at the DB level.
I can totally hardcode the statement in the servlet or JSP and it will return one value potentially several times, but only one.
Other times, it will not return a value at all, even though one resides in the db.
Yet go to the DB/SQL Plus prompt and it returns perfectly. I can simply copy and paste the SELECT statement from the out.print line I made and it works like a champ in SQL Plus. Any ideas why the same exact thing cannot return the proper values within the servlet/JSP?
Yeeeeeeesh!!! : (
Message was edited by:
bpropes20 -
Does the column selected in the select statement will effect the table access. I have a query selecting 10 columns from different tables using joins and inline views. One table is going for a Full table Scan.
When I searched for the cause, I couldn't find anything. Everything looks correct. When I comment 2 two particular columns from the select statement the table is not scanned fully.
Those two columns are not the part of the index. Why does a selection of columns affect the Explain plan?
Thanks,
GMHi Gints,
Thank you for your reply. This is my query and
nvl(TICKET_JOIN.TDQRLV,0) ACC_SHIPPED_QTY,
TICKET_JOIN.TDSOQS QUANTITY_TICKETED are the columns tha's creating issue. If I comment those columns Index is accessed properly.
select
'TKT' SOURCE,
TICKET_JOIN.TKDO01 HIRE_ID,
TICKET_JOIN.TKQ101 TRUCK_ID,
TICKET_JOIN.TKVEHT TRUCK_TYPE,
1 TRUCK_COMM,
nvl(TKCMP1,0) TICKET_NUM,
nvl(TKADTM,0) TICKET_TIME,
--TICKET_JOIN.TDSOQS QUANTITY_TICKETED,
0 CHECKIN_TIME,
--nvl(TICKET_JOIN.TDQRLV,0) ACC_SHIPPED_QTY,
nvl(DDADTM,0) START_TIME
from
(select
TICKET.TKCMP1,
TICKET.TKDO01,
TICKET.TKQ101,
TICKET.TKADTM ,
TICKET.TKVEHT,
TICKET_DETAILS.TDAITM ,
TICKET_DETAILS.TDQRLV ,
TICKET_DETAILS.TDSOQS ,
TICKET.TKCNTF,
TICKET.TKTRDJ,
TICKET.TK58GA8
from
CRPDTA.F5800091 TICKET_DETAILS ,
CRPDTA.F5800090 TICKET
where TICKET.TKCMP1 = TICKET_DETAILS.TDCMP1
and TICKET.TKTRDJ = TICKET_DETAILS.TDTRDJ
and TICKET.TKTRDJ = 107085
and TICKET.TKEV12 <> 'Y'
and TICKET.TK58GA8='ECSEO'
and TICKET.TKCNTF = '11') TICKET_JOIN ,
(select
DDDOCO,
DDCNTF,
DDQTFN,
DDAITM,
DDADTM,
DD58GA8,
DDTRDJ
from
CRPDTA.F5800051 ORDER_DETAILS,
CRPDTA.F5800050 ORDER_HEADER
where
ORDER_HEADER.DHDOCO = ORDER_DETAILS.DDDOCO
and ORDER_HEADER.DHTRDJ = ORDER_DETAILS.DDTRDJ
and ORDER_HEADER.DH58GA8 = ORDER_DETAILS.DD58GA8
and ORDER_HEADER.DHDCTO = ORDER_DETAILS.DDDCTO
/*and
(ORDER_HEADER.DHTRDJ = 107085
OR (ORDER_HEADER.DHTRDJ = 107084 and ORDER_HEADER.DHEV04='Y')
and TRIM(ORDER_HEADER.DH58GA8) = 'ECSEO'
and TRIM(ORDER_DETAILS.DDCNTF) = '11' ) ORDER_VIEW
where TICKET_JOIN.TKTRDJ = ORDER_VIEW.DDTRDJ
and TICKET_JOIN.TDAITM = ORDER_VIEW.DDAITM
and TICKET_JOIN.TKCNTF = ORDER_VIEW.DDCNTF
and TICKET_JOIN.TK58GA8 = ORDER_VIEW.DD58GA8
and NOT EXISTS ( select 1 from CRPDTA.F5800120 TRUCK_ASSIGNMENT
where TATRDJ = 107085
and TACNTF = '11'
and TA58GA8 = 'ECSEO'
and TICKET_JOIN.TKQ101||TICKET_JOIN.TKVEHT = TAQ101||TAVEHT )
Thanks
GM -
Adding columns in select statements
All if i have the following statement and i wanted to add the two volume columns in the select statement can i just do a A1.volume + A2.Volume as vol
SELECT A1.ORDERID,A1.MARKET,A1.GIMSG, A2.ORDERID,A2.MARKET,A2.TRADERID, A1.VOLUME, A2.VOLUME
FROM table1 A1 JOIN table2
ON A1.TRADEDATE = A2.TRADEDATENo that wouldnt work,
Error will be invalid no(error no ORA-01722)
but you can use pipe(||)
select col1||col2 as col from ......
ex: SQL> select e.ename||d.dname as result_col from emp e,dept d where e.deptno=d.deptno;
RESULT_COL
SMITHRESEARCH
ALLENSALES
WARDSALES
JONESRESEARCH
MARTINSALES
BLAKESALES
CLARKACCOUNTING
SCOTTRESEARCH
KINGACCOUNTING
TURNERSALES
ADAMSRESEARCH
RESULT_COL
JAMESSALES
FORDRESEARCH
MILLERACCOUNTING
14 rows selected.
Message was edited by:
user517498 -
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.
Maybe you are looking for
-
Unable to import cds after installing iTunes latest version 10.1.0.56
I downloaded iTunes 10.1.56 after having problems with the 10.1.0.54 version. I can only download the first 1/2 of song 1 and nothing from the rest of any cd. Under "time" for each song, my library says "Not available". When I click on it to listen i
-
Help with scripting a period in barcode between fields.
Good Morning, I need help scripting a barcode that has a period as a separator in between fields. I have 3 fields that I need all encoded in to one barcode and need a period as separators. EMPID FormName EMPSSN I need barcode to read as follows EMPID
-
Cinema 23" - is this normal/acceptable?
Hi, with a black background, the backlight is "bleeding" from the bottom. (see the picture: http://axu2.dnsalias.com/~axu/cinema.jpg ) there is total of 7 green, red and blue stuck pixels - but only 3 of them are barely visible other than totally bla
-
Hi everybody, I can't build my project because i have a problem with the mapping of field in a presentation, how i can map the field for a attribute on my BPM object? Thanks
-
Stanby Database on Deffierent OS
Hi Can i have a primary database on Windows 2003 32 bit and standby database on Windows 2003 64 bit or vice versa. Oracle version is 11.1.0.7, and will be same on both the servers. Thanks