Query -
SELECT B.TYPE,
B.TYPE_VAL,
B.COMP,
B.start,
B.end,
B.lt,
B.modify
FROM table B
WHERE B.start <= sysdate
AND B.end >= sysdate
AND TRIM(B.type_val) IN
('111-AAA')
ORDER BY B.type_val,
B.type,
B.comp DESC;
OUTPUT
+------+----------+------+-----------+------------+----+-----------------+
| TYPE | TYPE_VAL | COMP | START | END | LT | MODIFY |
+------+----------+------+-----------+------------+----+-----------------+
| AS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| AS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 68 | 3/8/2016 0:34 |
| BS | 111-AAA | ** | 6/16/2015 | 6/16/2015 | 7 | 6/16/2015 10:32 |
| CS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| CS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 13 | 3/8/2016 0:34 |
| HS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| HS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 13 | 3/8/2016 0:34 |
| MS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| MS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 13 | 3/8/2016 0:34 |
| OS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| OS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 13 | 3/8/2016 0:34 |
| PS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 13 | 3/8/2016 0:34 |
| PS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| S | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| S | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 13 | 3/8/2016 0:34 |
| VS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| VS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 13 | 3/8/2016 0:34 |
+------+----------+------+-----------+------------+----+-----------------+
If you notice the data being pulled is in form of latest one first then older one
.
For eg for TYPE AS
-
| AS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
| AS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 68 | 3/8/2016 0:34 |
Latest data i.e 5/10/2016 is first and then 3/8/2016. (MM/DD/YY format)
But there is one exception here, for TYPE PS
- 3/8/2016 is above 5/10/2016
unlike all the others.
| PS | 111-AAA | ** | 3/8/2016 | 12/31/9999 | 13 | 3/8/2016 0:34 |
| PS | 111-AAA | ** | 5/10/2016 | 12/31/9999 | 1 | 5/10/2016 11:12 |
According to my knowledge the latest one should ideally be on the top if the sort order are same (TYPE,TYPE_VAL and COMP are same, so no ordering).
My question here is - Why this particular record is being pulled in reverse order ? Shouldn't it be like how all the other million records are pulled? There must be SOME PARTICULAR reason why is this happening.
I know most of you will reference to the fact that Oracle has no particular way of returning rows but this isn't the case here.