0

On Exeuting Following Query:

SELECT ID
  FROM INSTITUTE
 WHERE MEMBER_ID IN (
    SELECT ID 
      FROM MEMBER 
     WHERE ID IN (765,769,753,774,778,779,781,790,799,809,
                  820,823,855,835,839,842,845,849,850,851)
    ORDER BY NAME ASC
)

I am getting following error:

ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error at Line: 5 Column: 81

How can I troubleshoot this bug???

1
  • 2
    Why are you nesting so many subselects? The issue is the ORDER BY in the second subselect. Commented Nov 9, 2011 at 13:56

7 Answers 7

3

Your ORDER BY is inside your subselect and therefore useless to the final order of the results but is causing your error.

Move it outside the subselect.

SELECT id
  FROM institute
 WHERE member_id IN
          (  SELECT id
               FROM MEMBER
              WHERE id IN ( 765, 769, 753, 774, 778, 779, 781, 790,
                            799, 809, 820, 823, 855, 835, 839, 842,
                            845, 849, 850, 851 )
          )
 ORDER BY name ASC

N.B.: I can only assume that name is a column in the institute table as otherwise the ORDER BY would be totally redundant. Therefore it should be ordering the main SELECT.

or remove it entirely...

SELECT id
  FROM institute
 WHERE member_id IN
          (  SELECT id
               FROM MEMBER
              WHERE id IN ( 765, 769, 753, 774, 778, 779, 781, 790,
                            799, 809, 820, 823, 855, 835, 839, 842,
                            845, 849, 850, 851 )
          )

Wouldn't this query be more efficient though?

SELECT i.id
  FROM institute i
 INNER JOIN member m
    ON (i.member_id = m.id)
 WHERE m.id IN ( 765, 769, 753, 774, 778, 779, 781, 790,
                 799, 809, 820, 823, 855, 835, 839, 842,
                 845, 849, 850, 851 )
Sign up to request clarification or add additional context in comments.

3 Comments

You are now ordering results by institute.name (if it exists), and I'm quite convinced that the OP wants the results order by member.name. Why not do a join on institute.member_id = member.id and remove the sub-select entirely?
@KlausByskovHoffmann it is possible - however, the OP never stated their intended use / output, so it would be a guess. But i agree that would be logical.
In trying to second guess the OP's table structure, not all answers are going to be perfect, it is just an approximation of what he is trying to achieve whilst removing the issue that has caused them to ask the question.
1

Your ORDER BY in the sub-select is useless. Consider joining the two tables instead, like this:

SELECT ID
FROM INSTITUTE i, MEMBER m
WHERE
i.MEMBER_ID = m.ID
AND i.MEMBER_ID IN
    (
        765,769,753,774,778,779,781,790,799,809,820,823,855,835,839,842,845,849,850,851
    )
ORDER BY m.NAME

Comments

0

order by should bu put out of the IN clause

SELECT ID
FROM INSTITUTE
WHERE MEMBER_ID IN (
SELECT ID FROM MEMBER WHERE ID IN (
765,769,753,774,778,779,781,790,799,809,820,823,855,835,839,842,845,849,850,851 )
)
ORDER BY NAME ASC

1 Comment

Everybody here seems to think that Institute has a name column?
0

Try this -

SELECT ID 
FROM INSTITUTE 
WHERE MEMBER_ID IN (
SELECT ID FROM MEMBER WHERE ID IN (765,769,753,774,778,779,781,790,799,809,820,823,855,835,839,842,845,849,850,851))
ORDER BY NAME ASC

I suspect you need the ORDER BY statement outside of the IN clause

1 Comment

Everybody here seems to think that Institute has a name column?
0
SELECT ID FROM INSTITUTE 
WHERE MEMBER_ID IN ( SELECT ID FROM MEMBER WHERE ID IN
( 765,769,753,774,778,779,781,790,799,809,820,823,855,835,839,842,845,849,850,851 )) ORDER BY NAME ASC;

Try this - your order by is in the wrong place.

2 Comments

Everybody here seems to think that Institute has a name column?
I thought this when writing the answer - but thought the best way to illustrate where an ORDER BY clause should be would be to illustrate by moving "NAME" outside to the main query. However i accept that there was no information supporting this decision.
0

This is likely because your ORDER BY clause occurs inside the outer MEMBER_ID IN(...) clause.

This query looks suspiciously as though it should be accomplished with a JOIN instead of two IN() clauses:

SELECT INSTITUTE.id
FROM 
  INSTITUTE JOIN MEMBER ON INSTITUTE.MEMBER_ID = MEMBER.ID
WHERE MEMBER.ID IN IN (765,769,753,774,778,779,781,790,799,809,820,823,855,835,839,842,845,849,850,851)
ORDER BY MEMBER.NAME ASC

Comments

0

The order by in the subquery is completely useless, it won't order the output at all. Remove it and it will work.

Btw, moving it outside won't give the expected result, except institute.name has the same values as member.name ;-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.