skyer2000 Posted May 18, 2009 Share Posted May 18, 2009 Here is my table: key_table keyid papid userid 4 7 0 2 1 0 1 2 0 2 2 0 3 2 0 6 2 0 7 19 0 3 19 0 2 3 0 1 0 1 2 0 1 2 0 2 3 0 2 What I'm trying to figure out is how to setup a query that will check for a papid (lets say 2), get the keyid's associated to that papid (which would be 1,2,3,6), then pull all userid's that also have that keyid (which would output 1,1,2,2). Any ideas on how to setup a query to do this? Quote Link to comment https://forums.phpfreaks.com/topic/158616-solved-need-help-with-a-query/ Share on other sites More sharing options...
kickstart Posted May 18, 2009 Share Posted May 18, 2009 Hi Quick play (untested) Crude method:- SELECT userid FROM key_table WHERE keyid IN (SELECT keyid FROM key_table WHERE a.papid = 2) More elegant method SELECT b.userid FROM key_table a JOIN key_table b ON a.keyid = b.keyid WHERE a.papid = 2 All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/158616-solved-need-help-with-a-query/#findComment-836573 Share on other sites More sharing options...
skyer2000 Posted May 18, 2009 Author Share Posted May 18, 2009 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/158616-solved-need-help-with-a-query/#findComment-836590 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.