Menggunakan Operator Perbandingan Di PostgreSQL

Macam-Macam Operator Perbandingan

PostgreSQL menyediakan beberapa macam-macam operator perbandingan, yaitu:
1. Operator sama dengan (=)
2. Operator tidak sama dengan (!=) atau (<>)
3. Operator lebih dari (>)
4. Operator lebih dari atau sama dengan (>=)
5. Operator kurang dari (<)
6. Operator kurang dari atau sama dengan (<=)

Contoh

Asumsikan Anda telah memiliki tabel pegawai dengan data-data berikut:

hr=# SELECT * FROM pegawai;
 id_pegawai |   nama_pegawai        | umur |    alamat
------------+-----------------------+------+----------------
 001        | Nursalim              |   20 | Brebes
 002        | Iskiyati              |   25 | Bandung
 003        | Nurul Hikmah          |   18 | Semarang
 004        | Naura Krasiva         |   15 | Jakarta
 005        | Ahmad Fathoni         |   20 | Yogyakarta
(5 rows)

Operator (=)

hr=# SELECT * FROM pegawai
hr-# WHERE id_pegawai = '001';
 id_pegawai |   nama_pegawai        | umur |     alamat
------------+-----------------------+------+-----------------
 001        | Nursalim              |   20 | Brebes
(1 row)

Operator (!=)

hr=# SELECT * FROM pegawai
hr-# WHERE id_pegawai != '001';
 id_pegawai |    nama_pegawai       | umur |     alamat
------------+-----------------------+------+-----------------
 002        | Iskiyati              |   25 | Bandung
 003        | Nurul Hikmah          |   18 | Semarang
 004        | Naura Krasiva         |   15 | Jakarta
 005        | Ahmad Fathoni         |   20 | Yogyakarta
(4 rows)

Operator (<>)

hr=# SELECT * FROM pegawai
hr-# WHERE id_pegawai <> '001';
 id_pegawai |    nama_pegawai       | umur |     alamat
------------+-----------------------+------+-----------------
 002        | Iskiyati              |   25 | Bandung
 003        | Nurul Hikmah          |   18 | Semarang
 004        | Naura Krasiva         |   15 | Jakarta
 005        | Ahmad Fathoni         |   20 | Yogyakarta
(4 rows)

Operator (>)

hr=# SELECT * FROM pegawai
hr-# WHERE umur > 20;
 id_pegawai |     nama_pegawai      | umur |      alamat
------------+-----------------------+------+-------------------
 002        | Iskiyati              |   25 | Bandung
(1 row)

Operator (>=)

hr=# SELECT * FROM pegawai
hr-# WHERE umur >= 20;
 id_pegawai |      nama_pegawai     | umur |     alamat
------------+-----------------------+------+-------------------
 001        | Nursalim              |   20 | Brebes
 002        | Iskiyati              |   25 | Bandung
 005        | Ahmad Fathoni         |   20 | Yogyakarta
(3 rows)

Operator (<)

hr=# SELECT * FROM pegawai
hr-# WHERE umur < 20;
 id_pegawai |     nama_pegawai      | umur |     alamat
------------+-----------------------+------+---------------------------------------
 003        | Nurul Hikmah          |   18 | Semarang
 004        | Naura Krasiva         |   15 | Jakarta
(2 rows)

Operator (<=)

hr=# SELECT * FROM pegawai
hr-# WHERE umur <= 20;
 id_pegawai |     nama_pegawai      | umur |       alamat
------------+-----------------------+------+--------------------------------------
 001        | Nursalim              |   20 | Brebes
 003        | Nurul Hikmah          |   18 | Semarang
 004        | Naura Krasiva         |   15 | Jakarta
 005        | Ahmad Fathoni         |   20 | Yogyakara
(4 rows)

                                                                    ~~~~ ### ~~~~

Sekian tutorial tentang Bagaimana Cara Menggunakan Operator Perbandingan Di PostgreSQL. Semoga bermanfaat & Happy Learning PostgreSQL Database.

Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment