I am setting up a MySQL database and will be querying it with PHP. Is is better to break the information up into multiple tables and do select queries on each of the tables; or is it better to put all the items in one table and do a single select query?
For example:
It will hold information on upto 7 cars; which would mean that their will be approximately 50 columns or so.
Table_design 1
----------------------
table_all
username
car1_make
car1_model
car1_year
car1_condition
car1_tires
car1_color
car2_make
car2_model
car2_year
car2_condition
car2_tires
car2_color
----------------------
Table_design 2
----------------------
table_1
username
car1_make
car1_model
car1_year
car1_condition
car1_tires
car1_color
table_2
username
car2_make
car2_model
car2_year
car2_condition
car2_tires
car2_color
----------------------
Three tables. This way you’re not limited to the amount of information you can add to a car. And you’re not limited to the number of cars a user can have access to.
If you ever need a spreadsheet of users, query the
userstable. If you ever need an inventory of cars, query thecarstable. If you ever need to know which cars each users are associated with, query theuserscars.See Database Normalization.