mysql - select rows in a one to many situation -


I think I'm stuck in this particular situation:

This is my The tables are:

item_table:
id | Items
1: one
2: b
3: C

attr_table:
attr | Item_id
1: 1
1: 2
2: 1
2: 3
3: 2
3: 3
I like To know whether it is technically possible to recover anything that is associated with attr = 1 and 3. Answer 'B' should be same Similarly, if I request an item which is associated with attr = 1 and 2, then, I should get 'A' only.

The thing is that attr_table might possibly have many rows and I just want to do a query

this question seems easy and because I am not able to answer it I'm quite upset.

I was hoping someone could give me smarter ...

The example is written for SQLServer but the query should work as wel in mysql.

The key is that the HAVING COUNT statement is equal to the qualities that are to match. If the properties should be (1, 2, 5), then you have to change the count to 3. @item_table table declaration (id integer primary key, item CHAR (1)) @attr_table table (aTTR integer, integer ITEM_ID) @item_table value (1, 'A') @item_table value Enter (2, 'B') in @item_table value (3, 'C') insert insert attr_table value (1, 1) into the @attr_table value (1, 2) into the @attr_table value (2 , 1) Insert the @attr_table value (2, 3) into the @attr_table value (3, 2) Check @ INSERT attr_table value from (@ 3, 3) @item_table I select the internal item @attr_table include a on a. Item_ID = i.id Where are items by a.Attr (1, 3) COUNT (a.Attr) group = 2


Comments