Mysql – How to show multiple names for one record but not duplicate the record

MySQLmysql-5.5PHP

I have a database structure like so:

Car
 - id   
 - carname
 - image
 - category
 - status

Parts
 - partid
 - partname

CarParts
 - carpartid
 - carid(fk)
 - partid(fk)
 - amountid(fk)

Category
 - id
 - categoryname

Amount
 - amountid
 - amountvalue

Right now this is what I am working on:

SELECT * FROM carparts
INNER JOIN car on carparts.carpartid = car.id 

INNER JOIN parts on parts.partid = carparts.carpartid

INNER JOIN amount on amount.amountid = carparts.amountid where status = 1

This returns duplicate records when there is more than one carpart in the carparts table. How can I combine the carparts.id and car.id to one row but still have multiple partname for that one record?

So what has to happen is that each car could have multiple car parts but when the query runs if there is more than one car part for one record it shows duplicate records with different partnames is there a way to have to one car with many partnames for that record?

Do i have to change the database structure or the query to do this?

Best Answer

you structure looks good . except that you could merge the amount to the part table . as every part is strictly associates with price.

also, only reason you will have duplicate rows is if any of your dimensions tables do not follow strict primary constraints.

Car
 - id (pk)
 - carname
 - image
 - category
 - status

Parts
 - partid (pk)
 - partname
 - amountValue

CarParts
 - carpartid (pk)
 - carid(fk)
 - partid(fk)
 - amountid(fk)

Category
 - id (pk )
 - categoryname