> -----Original Message----- > From: Kelvin Park [mailto:kelvinpark86@xxxxxxxxx] > > I have two tables that share product codes to relate data. > One table is called IMAGE, and another one is called the PRODUCT. > There are more than one image for every product, for example product > code 1122 will have 3 images and 4938 will have 5 images within the > IMAGE table. Since all my product information is stored in PRODUCT table > except for the image file names (e.g. 1122_1.jpg, 1122_2.jpg or > 4938_1.gif), I have to build the following query: SELECT * FROM PRODUCT, > IMAGE WHERE PRODUCT.productcode = IMAGE.productcode. However, this > causes a little problem. When I print out all the product information > with its images, more than one copy of a product is printed out (because > of multiple images for each product). I'm still looking for a way to > build a query string so that I could have only one image displayed per > product (so that a user can click on the product to view more images). > You could use a Group By to limit each PRODUCT SELECT * from PRODUCT, IMAGE where PRODUCT.productcode = IMAGE.produtcode group by PRODUCT.productcode You could do it via 2 selects (ie, the first query simply lists all items in PRODUCT, then within this loop, a second query lists all entries in IMAGES which have the productcode, with a "limit 1" in the query. Personally, I'd go with the Group By option, and be clever with your ORDER so the correct image gets selected. Regards Chris Aitken The Web Hub Designer and Programmer Phone : 02 4648 0808 Mobile : 0411 132 075 ------------------------------------------------- Making The Web Work........ The Web Hub http://www.thewebhub.com.au/ chris@xxxxxxxxxxxxxxxx ------------------------------------------------- Confidentiality Statement: This message is intended only for the use of the Addressee and may contain information that is PRIVILEDGED and CONFIDENTIAL. If you are not the intended recipient, dissemination of this communication is prohibited. If you have received this communication in error, please erase all copies of the message and its attachments and notify us immediately -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php