Thursday, July 3, 2008

DECODE and SUBSELECT in Oracle

//DECODE is like if statement if(column, equals, True, False)

SELECT a.bookid, a.warga_type, a.matrik,
decode(a.warga_type, 'S', (select b.nama from fasas b where b.matrik = a.matrik),
'P', (select c.nama from SUN.biodata c where c.matrik = a.matrik)) as nama
FROM BOOKING a
WHERE a.bookid = :as_id

One of my SQL codes (Modified), if WARGA_TYPE = 'S' it will select NAMA from FASAS table.
if WARGA_TYPE = 'P' it will select from table BIODATA for user SUN.

No comments: