this one will be achieved by the JOIN Queries . if u have any doubt please see this link.http://phpweby.com/tutorials/mysql/32 or o/w give me the table fields i will update.
and i hope this will help you..
for example,
1). mysql> SELECT * FROM products;
+----+--------------+--------------+
| id | product_name | manufacturer |
+----+--------------+--------------+
| 1 | Shoes | Company1 |
| 2 | Laptop | Company2 |
| 3 | Monitor | Company3 |
| 4 | DVD | Company4 |
+----+--------------+--------------+
4 rows in set (0.00 sec)
2). mysql> SELECT * FROM buyers;
+----+------+------------+----------+
| id | pid | buyer_name | quantity |
+----+------+------------+----------+
| 1 | 1 | Steve | 2 |
| 2 | 2 | John | 1 |
| 3 | 3 | Larry | 1 |
| 4 | 3 | Michael | 5 |
+----+------+------------+----------+
this will be the output.
mysql> SELECT buyers.buyer_name, buyers.quantity, products.product_name FROM buyer
s LEFT JOIN products ON buyers.pid=products.id where buyers.id=1;
+------------+----------+--------------+
| buyer_name | quantity | product_name |
+------------+----------+--------------+
|John | 1 | Laptop |
+------------+----------+--------------+