skip to Main Content

So, I am doing union on same table, table1 with 2 different set of queries. My first query should return results with type ‘test’ and 2nd query should return results irrespective of type. But when Iam executing below query my first query results is not coming on top. Is there any way to achieve that such that it should always show first query execution results on top?

     select * from table1 where tl='AAA' AND FT ='ABC' AND DATE='04-MAY-23 11:07:00' AND TYPE = 'TEST'
 UNION
 select * from table1  where tl='AAA' AND FT ='ABC' AND DATE='04-MAY-23 11:07:00' 

2

Answers


  1. Chosen as BEST ANSWER
    select * from table1 where tl='AAA' AND FT ='ABC' AND DATE='04-MAY-23 11:07:00' AND TYPE = 'TEST'
     UNION ALL
     select * from table1 where tl='AAA' AND FT ='ABC' AND DATE='04-MAY-23 11:07:00' 
    

    This was giving me expected results. Thanks @Thorsten Kettner


  2. Hope below query can help, we can set a order by value to fixed_number field and can do order by with that fixed_number field

    select *, 1 as fixed_number  from table1 where tl='AAA'  AND FT ='ABC' AND DATE='04-MAY-23 11:07:00' AND TYPE = 'TEST'
    UNION
    select *, 2 as fixed_number  from table1  where tl='AAA' AND FT ='ABC' AND DATE='04-MAY-23 11:07:00'
    ORDER BY fixed_number;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search