Jump to content

[SOLVED] mysql joins query.


nishantcm

Recommended Posts

Hi.

 

I am using php with mysql. I have a table cardtags. There are two columns- cardtagid and tagid.

 

Plz see the attached image. The page for tag A will contain 1,2,7,8,10,11

 

I want to display links to tags B and C in page for tag A. Here link for tag D will not be displayed because none of the items are overlapping.

Similarly, page for tag C will contain links to tags A, B, and D. So I want a query that will give me A,B,D as result when I have tag C as a parameter.

 

I think this can be done with joins. Can anyone help me with this?

 

Thanks.

Nishant

 

[attachment deleted by admin]

Link to comment
Share on other sites

I may not fully understand your problem from the description you gave but maybe a sub query is what you're after?

 

select cardtagid from cardtags where tagid='C';

 

Should give you a result of 5,6,7,8,9,13. So a query for all tagid's that have a cardtag in the list 5,6,7,8,9,13 would be something like...

 

Select distinct(tagid) from cardtags where cardtagid in (select cardtagid from cardtags where tagid='C');

 

which should give you A, B, C, D. Then to get rid of the tagid you used as a parameter, in this case C, add and tagid!='C' to the query...

 

Select distinct(tagid) from cardtags where cardtagid in (select cardtagid from cardtags where tagid='C') add and tagid!='C';

 

Hope that helps.

 

Link to comment
Share on other sites

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.