[EMAIL PROTECTED] wrote:

My suggestion: Don't use a subquery, use a temp table (
http://dev.mysql.com/doc/mysql/en/rewriting-subqueries.html)

CREATE TEMPORARY TABLE tmpDupes (KEY (`Barang`))
SELECT `Barang`
FROM Barang
GROUP BY Barang
HAVING count(1) >1;

Select b.`BrgId`, b.`Kode`, b.`Barang`
From Barang b
INNER JOIN tmpDupes d
       on d.`Barang`= b.`Barang`;

DROP TEMPORARY TABLE tmpDupes;

Sure it takes 3 statements but it's going to be MUCH faster than 54 seconds (possibly < 1 second). It's how the subquery *should* have executed your statement but I don't think it did.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine
Thanks, its works. This query took time 15ms. It's great!
I also found if i rewrite my statement like this :

Select b.`BrgId`, b.`Kode`, b.`Barang`
From Barang b
INNER JOIN
(SELECT `Barang` FROM Barang
GROUP BY Barang HAVING count(1) >1) d
       on d.`Barang`= b.`Barang`

...i will have 15 ms too.

Thanks again.

Hendro


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to