Jumat, 18 Desember 2015

Pengenalan Dasar Select Statement Pada MySQL

Pada tutorial MySQL kali ini, kita akan belajar tentang Dasar Dasar Select Statement Di MySQL. Select statement digunakan untuk menampilkan data (data retrieving) dari sebuah table.

Select Statement In MySQL

Sintak Dasar


Di bawah ini adalah sintak dasar Select statement di MySQL:

SELECT column_name1, column_name2, ..., column_nameN 
FROM table_name;

Penjelasan sintak:
  • column_name1, column_name2, dan seterusnya adalah kolom-kolom yang akan ditampilkan pada select statement.
  • table_name adalah nama table yang datanya akan ditampilkan.

Sintak diatas digunakan jika Anda ingin menampilkan kolom tertentu saja sesuai dengan kebutuhan. Jika Anda ingin menampilkan semua data di kolom, Anda dapat menggunakan tanda bintang '*' pada select statement seperti sintak dasar berikut ini:

SELECT * FROM table_name;


Contoh


Misalkan Anda telah memiliki table "tbl_employee" dengan data-data sebagai berikut:

+-------------+---------------+------------+-------------+------------+------------+--------+
| employee_id | employee_name | birth_date | birth_place | salary | department | gender |
+-------------+---------------+------------+-------------+------------+------------+--------+
| 1 | Ahmad Sofyan | 1990-01-01 | Bandung | 1750000.00 | IT | L |
| 2 | Ismail Saleh | 1986-12-12 | Pandeglang | 5000000.00 | ACC | L |
| 3 | Ferry Subekti | 1987-06-06 | Purwakarta | 4500000.00 | HRD | P |
| 4 | Iskiyati | 1988-07-07 | Brebes | 7500000.00 | FIN | P |
| 5 | Nurul Hikmah | 1989-08-08 | Purwokerto | 3750000.00 | FIN | P |
| 6 | Riyanto | 1983-02-02 | Subang | 4000000.00 | IT | L |
| 7 | Azka Nurul | 1984-03-03 | Bandung | 5000000.00 | HRD | P |
| 8 | Venny Maya | 1989-04-04 | Jakarta | 6500000.00 | IT | P |
| 9 | Ana Fauziyah | 1989-05-05 | Bekasi | 3700000.00 | ACC | P |
| 10 | Arya Adhi | 1980-09-09 | Magelang | 8000000.00 | FIN | P |
+-------------+---------------+------------+-------------+------------+------------+--------+

Dari data table diatas,
  • Tampilkan data employee_id, employee_name, dan salary dari table "tbl_employee"

    Jawaban

    mysql> SELECT employee_id, employee_name, salary
    -> FROM tbl_employee;
    +-------------+---------------+------------+
    | employee_id | employee_name | salary |
    +-------------+---------------+------------+
    | 1 | Ahmad Sofyan | 1750000.00 |
    | 2 | Ismail Saleh | 5000000.00 |
    | 3 | Ferry Subekti | 4500000.00 |
    | 4 | Iskiyati | 7500000.00 |
    | 5 | Nurul Hikmah | 3750000.00 |
    | 6 | Riyanto | 4000000.00 |
    | 7 | Azka Nurul | 5000000.00 |
    | 8 | Venny Maya | 6500000.00 |
    | 9 | Ana Fauziyah | 3700000.00 |
    | 10 | Arya Adhi | 8000000.00 |
    +-------------+---------------+------------+
    10 rows in set (0.00 sec)

  • Tampilkan data employee_name, birth_date, birth_place, dan gender dari table "tbl_employee"

    Jawaban


    mysql> SELECT employee_name, birth_date, birth_place, gender
    -> FROM tbl_employee;
    +---------------+------------+-------------+--------+
    | employee_name | birth_date | birth_place | gender |
    +---------------+------------+-------------+--------+
    | Ahmad Sofyan | 1990-01-01 | Bandung | L |
    | Ismail Saleh | 1986-12-12 | Pandeglang | L |
    | Ferry Subekti | 1987-06-06 | Purwakarta | P |
    | Iskiyati | 1988-07-07 | Brebes | P |
    | Nurul Hikmah | 1989-08-08 | Purwokerto | P |
    | Riyanto | 1983-02-02 | Subang | L |
    | Azka Nurul | 1984-03-03 | Bandung | P |
    | Venny Maya | 1989-04-04 | Jakarta | P |
    | Ana Fauziyah | 1989-05-05 | Bekasi | P |
    | Arya Adhi | 1980-09-09 | Magelang | P |
    +---------------+------------+-------------+--------+
    10 rows in set (0.00 sec)

  • Tampilkan semua data dari table "tbl_employee"

    Jawaban

    mysql> SELECT * FROM tbl_employee;
    +-------------+---------------+------------+-------------+------------+------------+--------+
    | employee_id | employee_name | birth_date | birth_place | salary | department | gender |
    +-------------+---------------+------------+-------------+------------+------------+--------+
    | 1 | Ahmad Sofyan | 1990-01-01 | Bandung | 1750000.00 | IT | L |
    | 2 | Ismail Saleh | 1986-12-12 | Pandeglang | 5000000.00 | ACC | L |
    | 3 | Ferry Subekti | 1987-06-06 | Purwakarta | 4500000.00 | HRD | P |
    | 4 | Iskiyati | 1988-07-07 | Brebes | 7500000.00 | FIN | P |
    | 5 | Nurul Hikmah | 1989-08-08 | Purwokerto | 3750000.00 | FIN | P |
    | 6 | Riyanto | 1983-02-02 | Subang | 4000000.00 | IT | L |
    | 7 | Azka Nurul | 1984-03-03 | Bandung | 5000000.00 | HRD | P |
    | 8 | Venny Maya | 1989-04-04 | Jakarta | 6500000.00 | IT | P |
    | 9 | Ana Fauziyah | 1989-05-05 | Bekasi | 3700000.00 | ACC | P |
    | 10 | Arya Adhi | 1980-09-09 | Magelang | 8000000.00 | FIN | P |
    +-------------+---------------+------------+-------------+------------+------------+--------+
    10 rows in set (0.00 sec)


Sekian tutorial singkat tentang Pengenalan Dasar Select Statement Pada MySQL. Semoga bermanfaat & Happy Learning MySQL Database.

Salam,

Nursalim

Bagikan

Jangan lewatkan

Pengenalan Dasar Select Statement Pada MySQL
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.