![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Merchant table: 253 merchants - each merchant has one primary category Category table: 161 categories with images (one image per category) Merchants pick one primary category, some categories are more popular than others, for instance the Dry Cleaners has the most merchants at 13. I need to pick out 2 different merchants, not in the same category, and put them in another table, so they will not get selected again for 30 days. Right now, I'm doing something like the below but I'm getting dupes: SELECT merchant, category, imgsrc FROM merchants JOIN category ON merchants.pricategory_id = category.id ORDER BY RAND() <-- this is where the difficulty is |
|
WHERE merchant NOT IN (SELECT merchant FROM usedmerchants WHERE DATEDIFF(CURDATE(),added) < 30 ) LIMIT 2 If the entire table schemas are needed, I will be a happy to post them. TIA. |
#3
| ||||
| ||||
|
|
On 13-05-2011 06:30, Adrienne Boswell wrote: ORDER BY RAND() <-- this is where the difficulty is Why do you think there's a difficulty here? |
|
min(i) | max(i) | count(i) | +--------+--------+----------+ 0 | 32 | 32 | +--------+--------+----------+ |
|
i | +----+ 24 | 0 | 2 | 30 | 23 | +----+ |
|
i | +----+ 29 | 19 | 27 | 23 | 32 | +----+ |
#4
| |||
| |||
|
|
Merchant table: 253 merchants - each merchant has one primary category Category table: 161 categories with images (one image per category) Merchants pick one primary category, some categories are more popular than others, for instance the Dry Cleaners has the most merchants at 13. I need to pick out 2 different merchants, not in the same category, and put them in another table, so they will not get selected again for 30 days. Right now, I'm doing something like the below but I'm getting dupes: SELECT merchant, category, imgsrc FROM merchants JOIN category ON merchants.pricategory_id = category.id ORDER BY RAND() <-- this is where the difficulty is WHERE merchant NOT IN (SELECT merchant FROM usedmerchants WHERE DATEDIFF(CURDATE(),added) < 30 ) LIMIT 2 |
![]() |
| Thread Tools | |
| Display Modes | |
| |