简体   繁体   中英

mysql n to m query

I have following table structure

table domains

 ID     | name        |
________________________
   1    | example.com |
________________________
   2    | example.net |
________________________
   3    | example.org |

table products

 ID     | group        |
________________________
   1    | furniture    |
________________________
   2    | electronics  |
________________________
   3    | toys         |

table transit

 Domain.ID     |Produkt.ID |
_____________________________
   1           |    3      |
_____________________________
   1           |    2      |
_____________________________
   3           |    1      | 

as variable I have the domain name and in function of this I would like to get all the related products to the domain.

example:domain =>example.com should give me back the properties of product table with ID's 2 and 3

Select domains.ID, name,group
from Transit Inner Join Domains ON
Transit.domainId = Domains.Id
INNER JOIN products  ON
Transit.productId = products.Id
Where domains.Name= ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM