Am trying to add a constant column to the select query which is quering an inner query.
Need your help with the query.

select *,'1' as flag from
(
    select ROW_NUMBER() OVER (PARTITION BY e_id ORDER BY birth_date DESC) as rn,wh.birth_date,e.*,
    xy.m_id from employee e 
                    inner join table2 xy on e.e_id=xy.employee_id
                    inner join table3 wc on e.e_id=wc.e_id 
                    left outer join  table4 wh on xy.e_id=wh.e_id 
        where  my_id='1234' 
 ) where rn=1;

The above query is throwing an error - ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"

But when I change the query as following (not changing the inner query) it works fine.

select '1' as flag ,birth_date,e_id,[some othe columns from the below tables] from
(
    select ROW_NUMBER() OVER (PARTITION BY e_id ORDER BY birth_date DESC) as rn,wh.birth_date,e.*,
    xy.m_id from employee e 
                    inner join table2 xy on e.e_id=xy.employee_id
                    inner join table3 wc on e.e_id=wc.e_id 
                    left outer join  table4 wh on xy.e_id=wh.e_id 
        where  my_id='1234' 
 ) where rn=1;

Is it not possible to add a constant column when quering all the columns, I mean when using * ?

Appriciate your help. Thanks :)

Have you tried "select '1' as flag,* from ..." ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.