Bongkar-bongkar, nemu catatan lama yang masih valid. Diupload disini biar gak ilang dan gak lupa (Faktor U) 🙂
Catatan ini menjabarkan bagaimana menampilkan data yang unique dari sebuah tabel MySQL. Berikut adalah contoh data yang dimaksud:
ID | Nama | Alamat |
---|---|---|
11 | adi | medan |
12 | jack | yuke |
44 | penan | penayong |
11 | adi | medan |
87 | jme | malay |
44 | penan | penayong |
11 | adi | medan |
12 | jack | yuke |
13 | adi | medan |
Untuk menyelesaikan permasalahan ini, saya mencreate satu database dengan nama “unique“, 1 tabel dengan nama “test” dengan struktur dan data di atas.
Berikut capturannya:
[root@adisun ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3641 Server version: 5.1.52 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | unique | +--------------------+ 3 rows in set (0.00 sec) mysql> use unique; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +-----------------+ | Tables_in_unique | +-----------------+ | test | +-----------------+ 1 row in set (0.00 sec) mysql> select * from test; +-----+-------+----------+ | ID | Nama | Alamat | +-----+-------+----------+ | 11 | adi | medan | | 12 | jack | yuke | | 44 | penan | penayong | | 11 | adi | medan | | 87 | jme | malay | | 44 | penan | penayong | | 11 | adi | medan | | 12 | jack | yuke | | 13 | adi | medan | +-----+-------+----------+ 9 rows in set (0.00 sec) mysql> select distinct Nama from test; +-------+ | Nama | +-------+ | adi | | jack | | penan | | jme | +-------+ 4 rows in set (0.00 sec) mysql> select distinct ID,Nama,Alamat from test; +-----+-------+----------+ | ID | Nama | Alamat | +-----+-------+----------+ | 11 | adi | medan | | 12 | jack | yuke | | 44 | penan | penayong | | 87 | jme | malay | | 13 | adi | medan | +-----+-------+----------+ 5 rows in set (0.00 sec)
Semoga Bermanfaat 🙂
Post A Reply