403 Forbidden

Selasa, 28 Juli 2015

Menampilkan Hanya Data yang Sama/Duplikat di SQL


Ane punya tabel Buku degan record sbg berikut
+----+-----------------------------------+------------------------+------------+
| id | judul                             | penulis                | terbitan   |
+----+-----------------------------------+------------------------+------------+
|  1 | SQL Script                        | Johan Paul Celay       | 2014-04-18 |
|  2 | SQL PHP                           | Eko Riyanto            | 2015-05-10 |
|  3 | Javacsript tutorial               | Paul Sanjay            | 2010-10-08 |
|  4 | Java Netbeans                     | Widi Sanjaya Putra     | 2009-12-09 |
|  5 | Pem. Web Dinamis                  | Widi Ardiyanto         | 2011-10-10 |
|  6 | C# for Beginner                   | Yuki Kashiwagi Sanjaya | 2013-03-13 |
|  7 | Artifical Intellegence C++        | Okada Nana             | 2015-05-10 |
|  8 | Unity Game Developer for Beginner | Sahar Nakayama         | 2013-10-08 |
|  9 | Kumpulan Algortima                | Ahmad Rizaldi          | 2007-12-05 |
| 10 | HKT48 History Rewiew              | Mayu watanabe          | 2009-12-20 |
+----+-----------------------------------+------------------------+------------+

yang ane kasih warna merah itu adalah record yang mempunyai data 'terbitan' yang sama. dan ane cuma mau nampilin data yang sama itu. ini perintahnya

select a.* from buku a inner join(select terbitan,count(*) as count from buku group by terbitan having count(*)>1) b on a.terbitan=b.terbitan;

dan hasilnya adalah
+----+----------------------------+-------------+------------+
| id | judul                      | penulis     | terbitan   |
+----+----------------------------+-------------+------------+
|  2 | SQL PHP                    | Eko Riyanto | 2015-05-10 |
|  7 | Artifical Intellegence C++ | Okada Nana  | 2015-05-10 |
+----+----------------------------+-------------+------------+

referensi: http://stackoverflow.com/questions/2594829/finding-duplicate-values-in-a-sql-table


EmoticonEmoticon