SQL : Using Column Alias to Clarify Field Header

Friday, March 7, 2008

Scroll to English Version


SQL: Menggunakan Column Alias untuk memperjelas Field Header


Jika table anda mempunyai field yang kurang deskripstip anda mungkin akan
mempertimbangkan untuk menggunakan tips yang akan saya berikan ini. sebenarnya tips ini untuk anda yang sering atau terbiasa menggunakan sql editor/ atau DBA (Database Administration) Tools untuk melakukan query data. Misalnya anda mempunyai sebuah table bernama Persons dengan struktur sebagai berikut (saya gunakan struktur di Oracle) :




FNAME VARCHAR2(15),

LNAME VARCHAR2(15),

GENDER CHAR(1),

BIRTHDATE DATE



dan table tersebut mempunyai data sebagai berikut :




FNAME LNAME GENDER BIRTHDATE
--------------- --------------- ---------- ---------
KURT COBAIN M 20-FEB-67
IGOR CAVALERA M 04-SEP-70
AMY LEE F 13-DEC-81
COREY TAYLOR M 18-DEC-73


coba anda gunakan SQL statement dibawah ini :





select fname,lname,gender,birthdate from persons



maka hasilnya adalah :




SQL> select fname,lname,gender,birthdate from persons;

FNAME LNAME GENDER BIRTHDATE
--------------- --------------- ---------- ---------
KURT COBAIN M 20-FEB-67
IGOR CAVALERA M 04-SEP-70
AMY LEE F 13-DEC-81
COREY TAYLOR M 18-DEC-73

disitu terlihat bahwa kolom FNAME dan LNAME kurang deskriptip. agar lebih jelas dalam output query anda bisa menggunakan column alias. berikut ini contoh syntax statement sql di beberapa database SQL.



SQL statement in Oracle, MySQL, Paradox




select fname "First Name", lname "Last Name",gender,birthdate

from persons



output query-nya :





SQL> select fname "First Name",
2 lname "Last Name", gender, birthdate
3 from persons;

First Name Last Name GENDER BIRTHDATE
--------------- --------------- ---------- ---------
KURT COBAIN M 20-FEB-67
IGOR CAVALERA M 04-SEP-70
AMY LEE F 13-DEC-81
COREY TAYLOR M 18-DEC-73




SQL statement in Microsoft Access and Microsoft SQL Server




select fname as [First Name], lname as [Last Name],gender,birthdate

from persons



Maka output query-nya akan sama dengan output sql yang saya gunakan di oracle, MySQL dan Paradox sebelumnya.













Scroll to Indonesian Version

If you have tables that the field are less descriptive, you may want to consider this tips that i will explain below. actually this tips is for you who often use sql editor or DBA (Database Administration) Tools to do queries. for example you have a table called Persons with the following structure (i use a structure in oracle database) :





FNAME VARCHAR2(15),

LNAME VARCHAR2(15),

GENDER CHAR(1),

BIRTHDATE DATE



and this table have the following data :



FNAME LNAME GENDER BIRTHDATE
--------------- --------------- ---------- ---------
KURT COBAIN M 20-FEB-67
IGOR CAVALERA M 04-SEP-70
AMY LEE F 13-DEC-81
COREY TAYLOR M 18-DEC-73


try use this SQL Statement below :




select fname,lname,gender,birthdate from persons



The SQL statement result output are :



SQL> select fname,lname,
2 gender,birthdate from persons;

FNAME LNAME GENDER BIRTHDATE
--------------- --------------- ---------- ---------
KURT COBAIN M 20-FEB-67
IGOR CAVALERA M 04-SEP-70
AMY LEE F 13-DEC-81
COREY TAYLOR M 18-DEC-73


in the sql statement result output above we can see that FNAME and LNAME column are less descriptive. for more clearly column header in the query output you can use a column aliases. the following is an example of sql statement syntax for using column aliases in several sql database engine.



SQL statement in Oracle, MySQL, Paradox




select fname "First Name", lname "Last Name",

gender,birthdate from persons



The SQL statement result output :





SQL> select fname "First Name",

2 lname "Last Name", gender, birthdate
3 from persons;

First Name Last Name GENDER BIRTHDATE
--------------- --------------- ---------- ---------
KURT COBAIN M 20-FEB-67
IGOR CAVALERA M 04-SEP-70
AMY LEE F 13-DEC-81
COREY TAYLOR M 18-DEC-73



SQL statement syntax in Microsoft Access and Microsoft SQL Server




select fname as [First Name], lname as [Last Name],gender,birthdate

from persons



sql statement above will bring the same result output as sql statement that we use in Oracle, MySQL and paradox previously.

0 comments:

Recent Comments

Tags Cloud

Blogumulus by Roy Tanck and Amanda Fazani