Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query of multiple tags help

Status
Not open for further replies.

Convictions

Programmer
Mar 29, 2008
3
First, thank you for taking the time to read this.

I have a table named `Tags` which consists of my site members tags (words stripped from their about me sections) - this table has two columns: Tag, profile.
Tag is the word, profile is the ID of the member.

I am trying to have a query that outputs a member's tags that at least matches one other member's tag in the database. I have tried everything I can think of. Here is my code, and error generated:

Code:
        $sTagsQuery = "SELECT `Tag` as `user_tag` FROM `Tags` WHERE `Tags`.`profile`='{$p_arr['ID']}' AND EXISTS
                      (SELECT `Tag` FROM `Tags` WHERE `Tag` = `user_tag` AND COUNT( `Tags`.`Tag` ) > 2 GROUP BY `Tags`.`Tag`)";
        $rTags = db_res( $sTagsQuery );
        while( $aTags = mysql_fetch_assoc( $rTags ) )
        {
        $sTagsAddon .= "<a href='" . $site['url'] . "search_result.php?tag=" . $aTags['user_tag'] . "'>" . $aTags['user_tag'] . "</a>, ";
        }

The error is:

Query:
SELECT `Tag` as `user_tag` FROM `Tags` WHERE `Tags`.`profile`='1' AND EXISTS
(SELECT `Tag` FROM `Tags` WHERE `Tag` = `user_tag` AND COUNT( `Tags`.`Tag` ) > 2 GROUP BY `Tags`.`Tag`)

Mysql error:
Invalid use of group function


Any help will be greatly appreciated!
Thank you,
Chris
 
select
distinct a.profile,a.tag
from tags a inner join tags b using(tag)
where a.profile<>b.profile;

to retrieve only those tags that match
or

select
*
from tags where profile in
(
select
distinct a.profile
from tags a inner join tags b using(tag)
where a.profile<>b.profile
);

to retrieve all records of an individual where at least one of their tags matches at least one tag of another individual
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top