nishantcm Posted July 21, 2008 Share Posted July 21, 2008 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] Quote Link to comment Share on other sites More sharing options...
ann Posted July 21, 2008 Share Posted July 21, 2008 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. Quote Link to comment Share on other sites More sharing options...
nishantcm Posted July 21, 2008 Author Share Posted July 21, 2008 A frnd helped me with this. Heres the query SELECT DISTINCT t1.set FROM table t LEFT JOIN table t1 ON t.item = t1.item WHERE t.set = 'A' AND t1.set <> 'A' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.