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

Find IDs with more than x cats, find equal datasets in CatLinks

Quote Reply
Find IDs with more than x cats, find equal datasets in CatLinks
While i have build a lot of code around my Links i made some mistakes in the past.
Now i have to find all double entrees in CatLinks, but i stuck with the correct SQL for that.
The same i have to find all IDs with more than x Cats.

Is there an easy SQl-Statement for this?
Quote Reply
Re: [Robert] Find IDs with more than x cats, find equal datasets in CatLinks In reply to
Hi Robert,

This one should be working:

select LinkID,count(*) as count from glinks_CatLinks group by LinkID having count > 1;

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Find IDs with more than x cats, find equal datasets in CatLinks In reply to
Yes, Sir. That helps. :)

And i have solved another where ...
Code:
select LinkID, count(*) as count from CatLinks, Links
WHERE Car = 'red' AND CatLinks.LinkID = Links.ID
group by LinkID having count > 1

But how i can ask

Choose all LinkID from CatLinks with more than 1 Cat and one CategoryID of them is '123' ?
Quote Reply
Re: [Robert] Find IDs with more than x cats, find equal datasets in CatLinks In reply to
Hi Robert,

If you want to select record from a particular category, just add another and condition to the where clause. Some thing like below:

Code:
select LinkID, count(*) as count from CatLinks, Links
WHERE Car = 'red' AND CatLinks.LinkID = Links.ID and CatLinks.CategoryID=123
group by LinkID having count > 1

Cheers,

Dat

Programming and creating plugins and templates
Blog