Ok, this is quite difficult to explain but I'll give it a go.
First of all, I have a table called 'Products' and I want to display one product on a page along with other information about that product gathered from related tables. The information gathered from other tables will not always be possible because a piece of information for a product may not be set so I cannot do one query to gather all the information because matches won't necessarily turn up for each table.
For instance, the products have manufacturers and the manufacturers are stored on another table. The product may not have a manufacturer alocated to it i.e:
That would be the query I could run to gather both pieces of information. However, if the product did not have a manufacturer set to it, how can I still make the table yield information about the product on its own without having to re-query the database to see if it does or doesn't have a manufacturer? (baring in mind I may have multiple relational tables I want to query which are not essential values but I don't want to keep re-querying, I'd rather just have one query if possible)
I'm not familiar with table JOIN or GROUP in MySQL, so those could perhaps be the answer to the problem, I don't know!
Anyway, I hope I have explained the problem and I'm sure it's a pretty common bridge developers have to cross. Anyone know how to cross this bridge!?
Thanks
First of all, I have a table called 'Products' and I want to display one product on a page along with other information about that product gathered from related tables. The information gathered from other tables will not always be possible because a piece of information for a product may not be set so I cannot do one query to gather all the information because matches won't necessarily turn up for each table.
For instance, the products have manufacturers and the manufacturers are stored on another table. The product may not have a manufacturer alocated to it i.e:
Code:
SELECT p.product_id, p.product_name, p.manufacturer_id, m.manufacturer_id, m.manufacturer_name
FROM products AS p, manufacturers AS m
WHERE p.product_id = 20 AND m.manufacturer_id = p.manufacturer_id
That would be the query I could run to gather both pieces of information. However, if the product did not have a manufacturer set to it, how can I still make the table yield information about the product on its own without having to re-query the database to see if it does or doesn't have a manufacturer? (baring in mind I may have multiple relational tables I want to query which are not essential values but I don't want to keep re-querying, I'd rather just have one query if possible)
I'm not familiar with table JOIN or GROUP in MySQL, so those could perhaps be the answer to the problem, I don't know!
Anyway, I hope I have explained the problem and I'm sure it's a pretty common bridge developers have to cross. Anyone know how to cross this bridge!?
Thanks