Jump to content

Recommended Posts

Hi, I'm new to MySQL and was wondering if you could help me with whats hopefully quite a simple issue...

 

I have a database with three tables:

table1: pages with an 'pageid' field and a 'pagebody' field.

table2: tag terms with a 'tagid' and 'tagname' field.

table3: one which links the pages with their tags ('pageid' and 'tagid')

 

One page can be tagged with multiple terms and it's 'pageid' will therefore appear several times in table3 with it's various 'tagid's.

 

Now I realise that if I wanted all the 'pageid's tagged with 'tagid' 17 for example, I can just say:

 

SELECT * FROM table3 WHERE tagid = 17

 

but what if I want the all the 'pageid's that are tagged with say 17 AND 23 AND 44? So it only shows me the pages that have an association with all three tags in table3.

 

This seems like it should be simple but I can't work out a way of doing it without the same 'pageid' appearing multiple times in the results.

 

I hope this makes sense, any help would be greatly appreciated...

 

 

Link to comment
https://forums.phpfreaks.com/topic/237516-mysql-newbie-with-a-tagging-query/
Share on other sites

Ok, it looks like you're on to something there... I still can't quite get it working though, lets say for example table3 looks like this:

 

pageid  tagid

1 ------- 3

1 ------- 4

1 ------- 9

2 ------- 4

2 ------- 11

2 ------- 45

3 ------- 3

3 ------- 9

4 ------- 9

 

I need a query that will allow me to say 'give me all the pages tagged with 3 and 4'. The result of this query should be 1 because it's the only one tagged with both. Or, 'Give me all the pages tagged with 3 and 9. The result of this query should be 1 and 3... does this make sense??  :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.