[Wolves] MySQL - equi-join DISTINCT

David Goodwin david at codepoets.co.uk
Wed Jul 18 12:41:28 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Philip Harper wrote:
> $last = mysql_query("SELECT DISTINCT * FROM user, userlog WHERE
> userlog.username = user.username LIMIT 0, 20") or die(mysql_error());
> 
> This SQL works, but still returns 4 records, the total number of records
> in the table userlog, so the DISTINCT clause isn't filtering out the
> duplicates in table userlog, anyone any ideas where DISTINCT goes in the
> join?
> 


I don't quite understand the problem; distinct removes duplicates in the
entire resultset.
i.e.

a,a,a
a,a,a
b,a,a
a,b,a
a,a,b

would become :

a,a,a
b,a,a
a,b,a
a,a,b

David.

- --
David Goodwin

[ david at codepoets dot co dot uk ]
[ http://www.codepoets.co.uk       ]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGnfxh/ISo3RF5V6YRAtwhAKC/72Tsu8rqMcpBIu53wI9SuCPL6wCgylp2
bnAO8tIH29cCI1cU/goNQis=
=XCea
-----END PGP SIGNATURE-----



More information about the Wolves mailing list