Single value data to multiple values of data in database relation

Posted by Sofiane Merah on Stack Overflow See other posts from Stack Overflow or by Sofiane Merah
Published on 2012-09-12T15:33:30Z Indexed on 2012/09/12 15:38 UTC
Read the original article Hit count: 440

I have such a hard time picturing this. I just don't have the brain to do it.

I have a table called reports.

---------------------------------------------
| report_id   | set_of_bads | field1 | field2 |
---------------------------------------------
| 123         | set1        | qwe    | qwe    |
---------------------------------------------
| 321         | 123112      | ewq    | ewq    |
---------------------------------------------

I have another table called bads. This table contains a list of bad data.

-------------------------------------
| bad_id    | set_it_belongs_to | field2 | field3  |
-------------------------------------
| 1         | set1              | qwe    | qwe     |
-------------------------------------
| 2         | set1              | qee    | tte     |
-------------------------------------
| 3         | set1              | q44w   | 3qwe    |
-------------------------------------
| 4         | 234               | qoow   | 3qwe    |
-------------------------------------

Now I have set the first field of every table as the primary key. My question is, how do I connect the field set_of_bads to set_it_belongs_to in the bads table. This way if I want to get the entire set of data that is set1 by calling on the reports table I can do it.

Example: hey reports table.. bring up the row that has the report_id 123. Okay thank you.. Now get all the rows from bads that has the set_of_bads value from the row with the report_id 123. Thanks.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql