Gossamer Forum
Quote Reply
UNIQUE?
Does anyone know how to use a 'UNIQUE' feature in Links SQL's GT::SQL ? I currently have;

Code:
# first of all, we need to get the list of categories...
my $table = $DB->table('News');
$table->select_options ('ORDER BY Category ASC');
my $sth2 = $table->select();
my ($cats,@cats);

# set $got to true if we managed to find an entry matcinhg their details...
my $count = 0;
while (my $hit = $sth2->fetchrow_hashref) {

if ($count == 0) {
push(@cats,$hit->{Category});
}

foreach (@cats) {
chomp;
if ($hit->{Category} eq $_) { next; } else { push(@cats,$hit->{Category}); }
}

}

The problem with this is that it takes ages to load, an sometimes times out (over 100 categories). Is there a better/faster way to do this? I know 'unique' would do the job....but I can't find any documentation on itworking with GT::SQL Unsure

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
Re: [Andy] UNIQUE? In reply to
It's not hard to find ;)

GT::SQL::Creator
GT::SQL::Editor
Quote Reply
Re: [Paul] UNIQUE? In reply to
Yeah, but I don't want to modify a field so that it only allows unique names; nor do I want to drop or add Wink I simply want to select only unique entries for the 'Category' field :/

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
Re: [Andy] UNIQUE? In reply to
Why didn't you say so Smile

Code:
$table->select( 'DISTINCT(Name)' )
Quote Reply
Re: [Paul] UNIQUE? In reply to
Wow...thats simple! Thanks loads, I'm sure that feature is going to be very useful in the future too Smile

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
Re: [Andy] UNIQUE? In reply to
When using the following;

my $sth2 = $table->select( 'DISTINCT(Title)', [ 'AccessString' ], $cond );

I get duplicated. Am I formatting the query wrong? I don't get any errors, and both Title and AccessString are accessable Unsure

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
Re: [Andy] UNIQUE? In reply to
Just do:

$sth = $table->select(['distinct(Title)'],$cond);
Mel Goulet
Developer - Gossamer Threads, Inc.
Quote Reply
Re: [Mel_g] UNIQUE? In reply to
Yeah, I tried that before, but then the field 'AccessString' is not available Unsure

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
Re: [Andy] UNIQUE? In reply to
$sth = $table->select(['distinct(Title)','AccessString'],$cond);
Quote Reply
Re: [afinlr] UNIQUE? In reply to
Already tried that. This is why I'm so confused Crazy If I use the above example, it gives me both 'AccessString' and 'Title', but duplicates occur. If I remove the ,'AccessString' part, it doesn't give duplicates, but AccessString is not available Unsure

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
Re: [Andy] UNIQUE? In reply to
Try this

$sth = $table->select([\'Distinct Title','AccessString'],$cond);
Quote Reply
Re: [afinlr] UNIQUE? In reply to
No results are returned when using the above code Frown

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
Re: [Andy] UNIQUE? In reply to
Well that's what I use in my code and it works for me Unsure. I'm out of suggestions now sorry.
Quote Reply
Re: [afinlr] UNIQUE? In reply to
I've managed to get around the problem by opening up a new select searching for a link that has the same title, and grabbing all the variables. Seems to be working well :) (although it obviously slows it down a bit more).

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
Re: [Andy] UNIQUE? In reply to
Andy,

I know this thread is old but having encountered exactly the same problem I read up on this a bit more.

It seems that DISTINCT applies to the whole row not the column (as far as I can see - someone please correct me if I'm wrong). So DISTINCT(Column) is misleading - it will actually search for distinct rows. This is fine if you are only returning one column. However, it is no good if you want several columns returned.

Suppose, for example, you have two columns

Col1 Col2

a 1

a 2

select (['DISTINCT Col1']) would just return 'a' but

select (['DISTINCT Col1', 'Col2']) would return both rows as it is actually looking for distinct Col1,Col2 combinations.

I assume that your column AccessString must have had different values for the same Title?

Laura.
Quote Reply
Re: [afinlr] UNIQUE? In reply to
What does this give you?

select (['DISTINCT Col1,Col2']);

If you look at your codes, it is running the DISTINCT on Col1, and then Col2 isn't actually assigned to anything, as its in seperate quotes.

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
Re: [Andy] UNIQUE? In reply to
I found this by playing around with it in SQL Monitor rather than using the GT code.

It isn't running DISTINCT on Col1, it is running it on the whole row - that's the point. DISTINCT only applies to the row and not the column whether you specify it as DISTINCT Col1, Col2 or DISTINCT(Col1), Col2 - or any other way.