c_shelswell Posted November 24, 2006 Share Posted November 24, 2006 Hi i'm sure this has a very simple answer. I'm looking to query mysql joining two tables. basically i have:Mediamedia_id - title - pictureand Purchasesmedia_id - quantityall im looking to do is query mysql for the title of the media_id i give to it from the purchases table. I'm getting some results but i provides me with the title as many times as the media_id appears in purchases i only need it once.Here's my code.[code]select media.title, media.picture from media left join purchases using (media_id) where purchases.media_id='4';[/code]i'm pretty new to mysql and this is really just a guess if anyone could help that would be great.Thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/28346-simple-query-in-mysql-that-i-cant-seem-to-get-right-joining-tables/ Share on other sites More sharing options...
c_shelswell Posted November 24, 2006 Author Share Posted November 24, 2006 Ooops managed to get it. I used this.[code]select distinct media.title, media.picture from media left join purchases on purchases.media_id=media.media_id where purchases.media_id=4;[/code]perhaps there's a better way? Quote Link to comment https://forums.phpfreaks.com/topic/28346-simple-query-in-mysql-that-i-cant-seem-to-get-right-joining-tables/#findComment-129658 Share on other sites More sharing options...
fenway Posted November 25, 2006 Share Posted November 25, 2006 That's fine, but I'm not sure why you have distinct. Quote Link to comment https://forums.phpfreaks.com/topic/28346-simple-query-in-mysql-that-i-cant-seem-to-get-right-joining-tables/#findComment-129888 Share on other sites More sharing options...
c_shelswell Posted November 25, 2006 Author Share Posted November 25, 2006 It seems if i don't have the "distinct" i get as many titles as there are purchases of that title in the purchases table. I'm only looking to get the name of it once. Quote Link to comment https://forums.phpfreaks.com/topic/28346-simple-query-in-mysql-that-i-cant-seem-to-get-right-joining-tables/#findComment-129992 Share on other sites More sharing options...
akitchin Posted November 25, 2006 Share Posted November 25, 2006 rather than DISTINCT, you could simply LIMIT your query to return one row (ie. LIMIT 1). Quote Link to comment https://forums.phpfreaks.com/topic/28346-simple-query-in-mysql-that-i-cant-seem-to-get-right-joining-tables/#findComment-130032 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.