Jump to content

Recommended Posts

I need a query that gets a list of member id who purchased products 1 and 87. I can not figure out the best way to do this. How can I do this?

 

Here is my table structure:

+----------------+------------------+------+-----+-------------------+-----------------------------+
| Field          | Type             | Null | Key | Default           | Extra                       |
+----------------+------------------+------+-----+-------------------+-----------------------------+
| recurring_id   | int(11)          | NO   | PRI | NULL              | auto_increment              |
| member_id      | int(11)          | NO   | MUL | 0                 |                             |
| product_id     | int(10) unsigned | YES  | MUL | NULL              |                             |
| special        | enum('ap')       | YES  |     | NULL              |                             |
| is_enabled     | tinyint(1)       | NO   | MUL | 0                 |                             |
| processor_id   | int(11)          | NO   | MUL | 0                 |                             |
| member_card_id | int(11)          | NO   |     | 0                 |                             |
| date_updated   | timestamp        | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+----------------+------------------+------+-----+-------------------+-----------------------------+

 

 

I thought that this query would work, but it doesn't:

select * from recurring where product_id in (87,1) group by member_id order by member_id limit 10;

 

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/248970-purchased-products-a-and-b/
Share on other sites

I'm thinking along the lines of:

SELECT * from recurring where ((member_id IN (SELECT member_id FROM recurring WHERE product_id = 87)) AND (member_id IN (SELECT member_id FROM recurring WHERE product_id = 1))) GROUP BY member_id ORDER BY member_id LIMIT 10

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.