database - SQL - field involving multiple rows from another table -
what i'm trying figure out surely answered before, can't find here (since i'm not sure should search for), bare me.
i have created/am creating 3 tables: slaves, citizens , incidents.
how should go incident involving multiple citizens , slaves? i'm thinking making 2 fields in incidents containing list of citizenid's , slaveid's (slaveid1, slaveid2...,slaveidn), seems plain dumb.
actually idea doesn't sound dumb @ all. can design incidents
table this:
+------------+-----------+---------+ | incidentid | citizenid | slaveid | +------------+-----------+---------+ | 1 | | | <-- incident #1 involved 2 citizens , 1 slave | 1 | b | | | 2 | | | <-- incident #2 involved 2 citizens , 2 slaves | 2 | b | | | 2 | | b | | 2 | | b | +------------+-----------+---------+
now when query incident id can obtain list of citizens , slaves involved in incident. many-to-many relationship in database schema.
Comments
Post a Comment