Home » SQL & PL/SQL » SQL & PL/SQL » Data not sorted (Oracle 19.2)
Data not sorted [message #685817] Fri, 01 April 2022 06:54 Go to next message
Unclefool
Messages: 47
Registered: August 2021
Member
Can someone please explain why my output is not coming out in sorted order?

I would have expected to see it sorted by B2, B3, B4, G3, G4, W4


create table inventoryItem (
       itemNum     varchar2(15) not null,
       code   varchar2(15) not null,
       qtyInstock integer       not null,
       itemColor  varchar2(15),
       itemSize   integer);
/

insert into inventoryItem (itemNum, code, qtyInstock, itemColor, itemSize) 
     select 'B3', 'pbk', 30, 'black', 3  from dual union all 
     select 'W4', 'hbk', 50, 'white', 4  from dual union all  
     select 'G4', 'hbk', 25, 'green', 4  from dual union all  
     select 'B3', 'hbk', 20, 'black', 3  from dual union all  
     select 'B4', 'ebk', 70, 'black', 4  from dual union all  
     select 'B2', 'pbk', 30, 'black', 2  from dual union all  
     select 'G3', 'pbk', 50, 'green', 3  from dual union all  
     select 'G4', 'ebk', 15, 'green', 4  from dual union all  
     select 'B3', 'pbk', 30, 'black', 3  from dual;
/

select itemNum
     , itemSize
     , itemColor
    , sum(qtyInstock )   as stock_combination
  from inventoryItem
GROUP  BY  itemNum,
 itemSize,  itemColor;
 order by itemNum,
 itemSize,  itemColor;

ITEMNUM    ITEMSIZE    ITEMCOLOR    STOCK_COMBINATION
G4    4    green    40
B2    2    black    30
G3    3    green    50
B4    4    black    70
W4    4    white    50
B3    3    black    80

Re: Data not sorted [message #685818 is a reply to message #685817] Fri, 01 April 2022 06:56 Go to previous messageGo to next message
Frank
Messages: 7892
Registered: March 2000
Senior Member
You have two semicolons in your query. The query ends before the order by
Re: Data not sorted [message #685820 is a reply to message #685818] Fri, 01 April 2022 07:35 Go to previous message
Unclefool
Messages: 47
Registered: August 2021
Member
Thanks. I should put in my glasses
Previous Topic: Oracle Update to get data from other tables using join
Next Topic: XML Generation
Goto Forum:
  


Current Time: Sun Jun 26 02:17:02 CDT 2022