Oracle ORDER BY in UNION
up vote
0
down vote
favorite
I have this query:
SELECT p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs)) AS "Info"
from profesori p JOIN didactic d ON d.id_prof = p.id_prof
JOIN cursuri c ON d.id_curs = c.id_curs
UNION
SELECT p.prenume||' '||p.nume||' ' AS "Info" from profesori p
JOIN didactic d ON p.id_prof NOT IN
(SELECT id_prof from didactic)
JOIN cursuri c ON c.id_curs NOT IN (SELECT id_curs from didactic) ORDER BY p.nume
How can I ORDER BY p.nume ? I get this error 'P"."NUME": invalid identifier'
I know I can order by Alias "Info" , but how can I order only by p.nume ?
oracle
|
show 2 more comments
up vote
0
down vote
favorite
I have this query:
SELECT p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs)) AS "Info"
from profesori p JOIN didactic d ON d.id_prof = p.id_prof
JOIN cursuri c ON d.id_curs = c.id_curs
UNION
SELECT p.prenume||' '||p.nume||' ' AS "Info" from profesori p
JOIN didactic d ON p.id_prof NOT IN
(SELECT id_prof from didactic)
JOIN cursuri c ON c.id_curs NOT IN (SELECT id_curs from didactic) ORDER BY p.nume
How can I ORDER BY p.nume ? I get this error 'P"."NUME": invalid identifier'
I know I can order by Alias "Info" , but how can I order only by p.nume ?
oracle
try SELECT * FROM (your query) ORDER BY Info
– BigMike
Nov 11 at 0:20
I get the same error .
– Robi_d
Nov 11 at 0:25
select also p.nume as "Nume" in your query execute in sql*plus (or any other program) the query and check how Oracle is naming the column, then add the order by.
– BigMike
Nov 11 at 0:30
I can't do that , its for a task . I need to select only 'p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs))' . I can't select p.nume too .. this is the problem
– Robi_d
Nov 11 at 0:32
1
Thanks man , OUTER JOIN was the solution .
– Robi_d
Nov 11 at 0:49
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have this query:
SELECT p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs)) AS "Info"
from profesori p JOIN didactic d ON d.id_prof = p.id_prof
JOIN cursuri c ON d.id_curs = c.id_curs
UNION
SELECT p.prenume||' '||p.nume||' ' AS "Info" from profesori p
JOIN didactic d ON p.id_prof NOT IN
(SELECT id_prof from didactic)
JOIN cursuri c ON c.id_curs NOT IN (SELECT id_curs from didactic) ORDER BY p.nume
How can I ORDER BY p.nume ? I get this error 'P"."NUME": invalid identifier'
I know I can order by Alias "Info" , but how can I order only by p.nume ?
oracle
I have this query:
SELECT p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs)) AS "Info"
from profesori p JOIN didactic d ON d.id_prof = p.id_prof
JOIN cursuri c ON d.id_curs = c.id_curs
UNION
SELECT p.prenume||' '||p.nume||' ' AS "Info" from profesori p
JOIN didactic d ON p.id_prof NOT IN
(SELECT id_prof from didactic)
JOIN cursuri c ON c.id_curs NOT IN (SELECT id_curs from didactic) ORDER BY p.nume
How can I ORDER BY p.nume ? I get this error 'P"."NUME": invalid identifier'
I know I can order by Alias "Info" , but how can I order only by p.nume ?
oracle
oracle
edited Nov 11 at 6:26
Madhur Bhaiya
17.7k62236
17.7k62236
asked Nov 11 at 0:16
Robi_d
41
41
try SELECT * FROM (your query) ORDER BY Info
– BigMike
Nov 11 at 0:20
I get the same error .
– Robi_d
Nov 11 at 0:25
select also p.nume as "Nume" in your query execute in sql*plus (or any other program) the query and check how Oracle is naming the column, then add the order by.
– BigMike
Nov 11 at 0:30
I can't do that , its for a task . I need to select only 'p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs))' . I can't select p.nume too .. this is the problem
– Robi_d
Nov 11 at 0:32
1
Thanks man , OUTER JOIN was the solution .
– Robi_d
Nov 11 at 0:49
|
show 2 more comments
try SELECT * FROM (your query) ORDER BY Info
– BigMike
Nov 11 at 0:20
I get the same error .
– Robi_d
Nov 11 at 0:25
select also p.nume as "Nume" in your query execute in sql*plus (or any other program) the query and check how Oracle is naming the column, then add the order by.
– BigMike
Nov 11 at 0:30
I can't do that , its for a task . I need to select only 'p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs))' . I can't select p.nume too .. this is the problem
– Robi_d
Nov 11 at 0:32
1
Thanks man , OUTER JOIN was the solution .
– Robi_d
Nov 11 at 0:49
try SELECT * FROM (your query) ORDER BY Info
– BigMike
Nov 11 at 0:20
try SELECT * FROM (your query) ORDER BY Info
– BigMike
Nov 11 at 0:20
I get the same error .
– Robi_d
Nov 11 at 0:25
I get the same error .
– Robi_d
Nov 11 at 0:25
select also p.nume as "Nume" in your query execute in sql*plus (or any other program) the query and check how Oracle is naming the column, then add the order by.
– BigMike
Nov 11 at 0:30
select also p.nume as "Nume" in your query execute in sql*plus (or any other program) the query and check how Oracle is naming the column, then add the order by.
– BigMike
Nov 11 at 0:30
I can't do that , its for a task . I need to select only 'p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs))' . I can't select p.nume too .. this is the problem
– Robi_d
Nov 11 at 0:32
I can't do that , its for a task . I need to select only 'p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs))' . I can't select p.nume too .. this is the problem
– Robi_d
Nov 11 at 0:32
1
1
Thanks man , OUTER JOIN was the solution .
– Robi_d
Nov 11 at 0:49
Thanks man , OUTER JOIN was the solution .
– Robi_d
Nov 11 at 0:49
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
How can I ORDER BY p.nume ?
With UNION queries we can only order by named columns in the projection of the first subquery. Your query only has nume
as a part of a concatenated column, hence the ORA-00904 error.
Sorting the UNION query by the columns in the result set means you can sort by your column alias...
order by "Info"
...which means it will effectively sort by prenume, nume, LOWER(REVERSE(c.titlu_curs))
.
The alternative solution - useful when you're not aliasing the sorting column - is to use the positional notation
order by 1
1
Alternatively,order by 1
would also work (meaning "sort by the first column" (which is "Info"). Though, that's probably not the best idea because people add columns and remove them, so "1" doesn't have to be the same column as it once was. I'd suggestorder by "Info"
.
– Littlefoot
Nov 11 at 13:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
How can I ORDER BY p.nume ?
With UNION queries we can only order by named columns in the projection of the first subquery. Your query only has nume
as a part of a concatenated column, hence the ORA-00904 error.
Sorting the UNION query by the columns in the result set means you can sort by your column alias...
order by "Info"
...which means it will effectively sort by prenume, nume, LOWER(REVERSE(c.titlu_curs))
.
The alternative solution - useful when you're not aliasing the sorting column - is to use the positional notation
order by 1
1
Alternatively,order by 1
would also work (meaning "sort by the first column" (which is "Info"). Though, that's probably not the best idea because people add columns and remove them, so "1" doesn't have to be the same column as it once was. I'd suggestorder by "Info"
.
– Littlefoot
Nov 11 at 13:03
add a comment |
up vote
1
down vote
How can I ORDER BY p.nume ?
With UNION queries we can only order by named columns in the projection of the first subquery. Your query only has nume
as a part of a concatenated column, hence the ORA-00904 error.
Sorting the UNION query by the columns in the result set means you can sort by your column alias...
order by "Info"
...which means it will effectively sort by prenume, nume, LOWER(REVERSE(c.titlu_curs))
.
The alternative solution - useful when you're not aliasing the sorting column - is to use the positional notation
order by 1
1
Alternatively,order by 1
would also work (meaning "sort by the first column" (which is "Info"). Though, that's probably not the best idea because people add columns and remove them, so "1" doesn't have to be the same column as it once was. I'd suggestorder by "Info"
.
– Littlefoot
Nov 11 at 13:03
add a comment |
up vote
1
down vote
up vote
1
down vote
How can I ORDER BY p.nume ?
With UNION queries we can only order by named columns in the projection of the first subquery. Your query only has nume
as a part of a concatenated column, hence the ORA-00904 error.
Sorting the UNION query by the columns in the result set means you can sort by your column alias...
order by "Info"
...which means it will effectively sort by prenume, nume, LOWER(REVERSE(c.titlu_curs))
.
The alternative solution - useful when you're not aliasing the sorting column - is to use the positional notation
order by 1
How can I ORDER BY p.nume ?
With UNION queries we can only order by named columns in the projection of the first subquery. Your query only has nume
as a part of a concatenated column, hence the ORA-00904 error.
Sorting the UNION query by the columns in the result set means you can sort by your column alias...
order by "Info"
...which means it will effectively sort by prenume, nume, LOWER(REVERSE(c.titlu_curs))
.
The alternative solution - useful when you're not aliasing the sorting column - is to use the positional notation
order by 1
edited Nov 11 at 13:12
answered Nov 11 at 10:06
APC
116k15114227
116k15114227
1
Alternatively,order by 1
would also work (meaning "sort by the first column" (which is "Info"). Though, that's probably not the best idea because people add columns and remove them, so "1" doesn't have to be the same column as it once was. I'd suggestorder by "Info"
.
– Littlefoot
Nov 11 at 13:03
add a comment |
1
Alternatively,order by 1
would also work (meaning "sort by the first column" (which is "Info"). Though, that's probably not the best idea because people add columns and remove them, so "1" doesn't have to be the same column as it once was. I'd suggestorder by "Info"
.
– Littlefoot
Nov 11 at 13:03
1
1
Alternatively,
order by 1
would also work (meaning "sort by the first column" (which is "Info"). Though, that's probably not the best idea because people add columns and remove them, so "1" doesn't have to be the same column as it once was. I'd suggest order by "Info"
.– Littlefoot
Nov 11 at 13:03
Alternatively,
order by 1
would also work (meaning "sort by the first column" (which is "Info"). Though, that's probably not the best idea because people add columns and remove them, so "1" doesn't have to be the same column as it once was. I'd suggest order by "Info"
.– Littlefoot
Nov 11 at 13:03
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244696%2foracle-order-by-in-union%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
try SELECT * FROM (your query) ORDER BY Info
– BigMike
Nov 11 at 0:20
I get the same error .
– Robi_d
Nov 11 at 0:25
select also p.nume as "Nume" in your query execute in sql*plus (or any other program) the query and check how Oracle is naming the column, then add the order by.
– BigMike
Nov 11 at 0:30
I can't do that , its for a task . I need to select only 'p.prenume||' '||p.nume ||' '||LOWER(REVERSE(c.titlu_curs))' . I can't select p.nume too .. this is the problem
– Robi_d
Nov 11 at 0:32
1
Thanks man , OUTER JOIN was the solution .
– Robi_d
Nov 11 at 0:49