0

I want to use alias in sub query but seems alias is not recognized in subquery

SELECT M.name, (select code from menus where menus.id = M.parent_id) as parent_code
    FROM menus as M;

How do I achieve this?

I used to use oracle and this query works.

1
  • The syntax is correct and will work in Postgres. See this online example: rextester.com/NBZS5678 What exactly does not work for you? What is the exact error message you get (edit your question, do not post code or additional information in comments). Commented Sep 18, 2017 at 8:49

1 Answer 1

1

Try this

SELECT m.name
FROM menus as m
WHERE m.parent_id in (
                        select m1.parent_id 
                       from menus as m1 
                       where m.parent_id = m1.parent_id
                      );
Sign up to request clarification or add additional context in comments.

1 Comment

That is something entirely different.

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.