mysql - How to select rows from a table that matches all the rows from a second table which has predicates? -


i have 2 tables, transaction table , transaction property table follows.

transaction table

create table `mydb`.`event` (   `id` int not null auto_increment,   `user` varchar(45) not null,   `type` int not null,    primary key (`id`)); 

property table

create table `mydb`.`event_property` (   `event_id` int not null,   `property_type` varchar(45) not null,   `value` varchar(45) not null,   primary key (`event_id`, `property_type`, `value`),   constraint `event_id`     foreign key (`event_id`)     references `mydb`.`event` (`id`)     on delete restrict     on update restrict); 

a single event may have multiple properties. want select event has 2 properties values. how this?

you can group by , having:

select event_id event_property property_type in ('1', '2') group event_id having count(distinct property_type) = 2; 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -