The Little Guy Posted February 27, 2007 Share Posted February 27, 2007 How do I select 4 distinct products from the database? This doesn't seem to work: SELECT DISTINCT PRODUCTS.*,IMAGES.* FROM IMAGES,PRODUCTS WHERE IMAGES.PRODUCT_NUM=PRODUCTS.PRODUCT_NUM ORDER by rand() LIMIT 4 Quote Link to comment Share on other sites More sharing options...
btherl Posted February 27, 2007 Share Posted February 27, 2007 What output do you get and what are you expecting? Also, do you have duplicate products? Or did you add the DISTINCT for another reason? If you do have duplicate products, what are the conditions for considering them to be "duplicate"? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 27, 2007 Author Share Posted February 27, 2007 I figured it out I just added another condition SELECT IMAGES.*,PRODUCTS.* FROM IMAGES,PRODUCTS WHERE IMAGES.PRODUCT_NUM=PRODUCTS.PRODUCT_NUM AND MAIN='1' ORDER by rand() LIMIT 5 Quote Link to comment Share on other sites More sharing options...
fenway Posted February 27, 2007 Share Posted February 27, 2007 DISTINCT wouldn't have worked ever anyway, since * will pull back the UIDs too. And you should use table prefixes for all columns; and join syntax wouldn't hurt, either. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.