Jump to content

reducing the number of queries


c0rnf3d

Recommended Posts

im sure theres a more efficient way to do what i need to, but i know not how to do it..

 

my table consists of 3 columns: user_id, question_id, answer_id

 

i want to query and find a user_id (or user_ids) that have my desired answer_ids (4+ desired answers)

 

basically i want to say something like "select * from answers where answer_id = '1' and answer_id='2' and answer_id = '3' and answer_id='4' " ---- and have this return to me a list of all users that have the desired answers im looking for

 

right now the only way i know how to do this is to

  • query = 'select * from answers where answer_id='1''
  • fetch the row and then another query: select * from answers where user_id = $row['user_id'] and answer_id = '2'
  • repeat the process with answer_id = '3' /4/5/6/

to me this seems inefficent and i assume can be done in 1 query, im just dont know how...

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.