1

I am implementing booking tool for process. There is inventory you can use - if you want to book process for a day AM and PM slot of this day is being used up. Then when calendar is being displayed, it brings all existing bookings showing for example that this room is not available in specific period of time.

Difficulty I am having is, that returned entries that are being displayed NOT in order so 'AM' slot after 'PM' slot. it all seem quite random it might be confusing for end user.

SELECT * FROM 
(
select 

query to select room 1 where slot is AM

UNION ALL

query to select room 1 where slot is PM

UNION ALL

query to select room 2 ( this room can be booked only for whole day )

)

ORDER BY slot ASC

this is structure of query I used. It returns entries correctly but not in order. I presume it is due to nested select statements.

What is the best approach to solve this problem?

2 Answers 2

1

Add a column to the inner queries and order the slots also by that column, like this:

SELECT * FROM 
(
   select 'AM' time_of_day,
   query to select room 1 where slot is AM
   UNION ALL
   select 'PM' time_of_day,
   query to select room 1 where slot is PM
   UNION ALL
   select 'WHOLE' time_of_day,
   query to select room 2 ( this room can be booked only for whole day )
)
ORDER BY slot ASC, time_of_day
4
  • Alen thank you for your answer. Unfortunately this approach does not work. Jan 22, 2013 at 10:16
  • @Lomo_effect What exactly is still wrong when using this solution? Or do you have diffuculties implementing it?
    – Tom
    Jan 22, 2013 at 11:40
  • I am sorry I should specify it more. My main concern is to retrieve records in ORDER( AM, AM, PM,PM) Above query does work however it is not sorting results in correct order. This is not purely SQL question as this solution needs to be implemented through APEX calendar tool. Jan 22, 2013 at 12:55
  • @Lomo_effect, it's still not clear why you think this solution does not work. "ORDER(AM, AM, PM, PM)" doesn't make sense. Perhaps you should post the sample data, results you're getting, the exact query you're using, and the expected results. Jan 23, 2013 at 7:45
1

After losing hope to over come this problem I accidentally stumbled across solution for the problem. Basically Apex calendar rely on date column but if there more than one record assigned to one day then it display them in random order. Some people suggested adding another column to add some ordering into it, however this would produce another layer of complexity which is not necessary. Solution:

SELECT ename, hiredate  +  rownum / 24 / 60 FROM 
(SELECT   ename, hiredate
    FROM emp
   ORDER BY ename)

by adding rownum parameter to date column Apex can pick up difference between records and suddenly everything works as it should be with normal order by.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.