반응형
/*******************************************************************************
-- Title : [PGS9.2] Example of NULLS {FIRST | LAST ]
-- Reference : postgresql.org
-- Key word : postgresql order by null first last 정렬 우선
*******************************************************************************/
-- Title : [PGS9.2] Example of NULLS {FIRST | LAST ]
-- Reference : postgresql.org
-- Key word : postgresql order by null first last 정렬 우선
*******************************************************************************/
-- Initiate
drop table ttt;
-- create table
create table ttt
( aa serial not null
, bb varchar(10) null
);
-- load data
insert into ttt(bb)
values ('ggg')
, (null)
, ('uuu')
, ('ddd')
, ('eee')
, ('kkk')
, ('aaa')
, (null)
, ('yyy');
-- query table
select * from ttt;
-- using "order by" using nulls first and last
select * from ttt order by bb asc; /*opposite sql server, same with 'nulls last'*/
select * from ttt order by bb asc nulls first;
select * from ttt order by bb asc nulls last;
select * from ttt order by bb desc;
select * from ttt order by bb desc nulls first;
select * from ttt order by bb desc nulls last; 반응형