Normalising sql

Soldato
Joined
24 Nov 2002
Posts
16,378
Location
38.744281°N 104.846806°W
I have a simple mysql table, for example:

Code:
Book              Genre
Veg is cool      1, 3, 4

And another table,

Code:
Genre              Def
1                     Factual
2                     Fiction
3                     Recipe book
4                     New
5                     Used

I naturally want to normalise this. Is there an intrinsic way to do this with sql (join?)? As I'm using php queries to do it at the moment.
 
Code:
Books:

book_id     book_title
1              Veg is cool
Code:
Genres:

genre_id           definition
1                     Factual
2                     Fiction
3                     Recipe book
4                     New
5                     Used
Code:
Genre holdings:

holding_id    book_id_rel      genre_id_rel
1                1                   1
2                1                   3
3                1                   4
The above structure is normalised, and you'd use joins to access the data.
 
Last edited:
Normalisation is a part of database design; it doesn't have anything to do with querying and SQL.

The psyr33n's schema is what you'd want to use to achieve 2NF/3NF though :)
 
Back
Top Bottom