[Wolves] MySQL - equi-join DISTINCT

Philip Harper ph004h7245 at blueyonder.co.uk
Wed Jul 18 15:24:39 BST 2007


Ah yes, that's it, exactly where I have gone wrong, as the DISTINCT is 
working on the entire result set, including the joined tables, there are 
actually no duplicate rows, I need to find another way that will only 
remove duplicates from user log and then join the non-duplicated records 
from userlog table with user table.

David Goodwin wrote:
> -----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-----
>
> _______________________________________________
> Wolves LUG mailing list
> Homepage: http://www.wolveslug.org.uk/
> Mailing list: Wolves at mailman.lug.org.uk
> Mailing list home: https://mailman.lug.org.uk/mailman/listinfo/wolves
>
>
>   





More information about the Wolves mailing list