Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

please tell me correct syntax of distinct

Quote Reply
please tell me correct syntax of distinct
Hello,

I have a problem to bring a SQL statement into the right syntax within a global:

I want to show the last 10 Links in certain categories. Some of these links are in two or more categories. And thats why my global shows them more then one time. But this isn't very useful.

I want to show only unique links for instance with SQL »distinct«. How do I do that, what is the correct syntax in a global?

My global:

lastlinks
sub {
my $id = shift;
my $db = $DB->table ('Links','CatLinks');
$db->select_options ('ORDER BY Add_Date DESC', 'LIMIT 10');
my $sth = $db->select ( { 'CatLinks.CategoryID' => ['7','8','9']}, [ 'Links.Title', 'Links.Add_Date'], { isValidated => 'Yes'} );
my @lasttenlinks;
while (my $link = $sth->fetchrow_hashref) {
push (@lasttenlinks, $link);
}
return { lastlinks_loop => \@lasttenlinks };
}

Thank you,

Stephan
Quote Reply
Re: [steve04] please tell me correct syntax of distinct In reply to
You could try;

my $sth = $db->select ( 'DISTINCT(Links.ID)', { 'CatLinks.CategoryID' => ['7','8','9']}, { isValidated => 'Yes'} );

Untested, but it should work (bear in mind its 7 am over here Wink).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Antwort: [Andy] Re: [steve04] please tell me correct syntax of distinct In reply to
So I did, before I had asked...

I've got the error message:

GT::SQL::Relation (12629): Bad columns / column clash: columns named 'DISTINCT(Links.ID)' have been found in current relation, please qualify your expression. at (eval 35) line 6.

I've tried with Links.ID in the list of selected fields and without. It doesn't work.

Stephan
Quote Reply
Re: [steve04] Antwort: [Andy] Re: [steve04] please tell me correct syntax of distinct In reply to
Mmm.. how about;

'DISTINCT(Links.ID)'

?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!