only1perky Posted December 9, 2010 Share Posted December 9, 2010 Hi Guys, Can someone please help me before I kill myself! I have a table holding details of images to be displayed in a gallery. The table has columns as 'id', 'image_caption', 'file_path', and 'userid'. The 'id' column is the unique key, and the 'userid' column is obviously id of the user who uploaded the image. What I would like to do is select and display one image from each unique userid and then display each image along with the details in my gallery. It doesn't really matter which users image is selected aslong as there is only one for each unique user. I have been trying a number of ways to do this (DISTINCT / subqueries) but I just cant get anything to work. Could someone please advise me on how I could get this to work. Cheers in advance. Quote Link to comment https://forums.phpfreaks.com/topic/221128-select-one-uinique-field-from-mysql/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 9, 2010 Share Posted December 9, 2010 Use - GROUP BY userid in your query. This will consolidate all the rows for each different userid into one row per userid. You will get the first row encountered for each userid. Quote Link to comment https://forums.phpfreaks.com/topic/221128-select-one-uinique-field-from-mysql/#findComment-1144963 Share on other sites More sharing options...
only1perky Posted December 16, 2010 Author Share Posted December 16, 2010 Thank you, I don't know why I didn't think of that before, I was really trying to over complicate things. Quote Link to comment https://forums.phpfreaks.com/topic/221128-select-one-uinique-field-from-mysql/#findComment-1148059 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.