MySQL Forums
Forum List  »  Newbie

select query for checkbox search filter
Posted by: Vladimir Pazdera
Date: March 18, 2016 10:03AM

Hello,

I have a table:

CREATE TABLE `currencies` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) unsigned NOT NULL,
`currency` int(11) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_user` FOREIGN KEY (`user_id`) REFERENCES user (`user_id`)
)

ID | USER_ID | CURRENCY
---------------------------------------
1 | 38 | EUR
2 | 38 | USD
3 | 38 | NOK
4 | 42 | EUR
5 | 42 | NOK
6 | 50 | USD

I'm trying to do search filter based on checkboxes with names of currency.
It would search in the table for all checked checkboxes related to user_id in the filter. So when for example currencies (EUR, USD, NOK) are checked then it would return only results of those users who has all three currencies. So in this case it would return only user_id #38. I tried to execute query "SELECT user_id FROM currencies WHERE currency IN ('EUR','USD','NOK')" but it returns results also when the user has just (USD), or (USD and EUR). Is there a way how to do it or my database structure are not so well constructed? Any suggestion how to to do it or rebuild the database will be appreaceated. Thanks in advance.

Options: ReplyQuote


Subject
Written By
Posted
select query for checkbox search filter
March 18, 2016 10:03AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.