i get 2 names as the output of the first query.... eg: paul,peter now this should be the input for the second query, which has to display paul's and peter's email ids....
For nested queries I would strongly recommend WITH
clause. It makes long complex queries order of magnitude easier to understand / construct / modify:
WITH
w_users AS( -- you can name it whatever you want
SELECT id
FROM users
WHERE < long condition here >
),
w_other_subquery AS(
...
)
SELECT email_id
FROM ...
WHERE user_id IN (SELECT id FROM w_users)