dflow Posted September 22, 2011 Share Posted September 22, 2011 trying to combine and execute this UPDATE `apartments` SET mainImage = (select DISTINCT(ImageURL) from images where ID LIMIT 1,1) WHERE InternalSupplierID=7; //while:Id needs to be distinct like the list bellow, the above inserts the first row continuously (SELECT DISTINCT(ID) FROM `apartments` WHERE `InternalSupplierID` =7) //need LEFT JOIN? Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/ Share on other sites More sharing options...
Muddy_Funster Posted September 22, 2011 Share Posted September 22, 2011 Your LIMIT 1,1 is why you are only ever getting the first row every time. What exactly do you want to happen? Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271700 Share on other sites More sharing options...
dflow Posted September 22, 2011 Author Share Posted September 22, 2011 i ahve a lis Your LIMIT 1,1 is why you are only ever getting the first row every time. What exactly do you want to happen? i need to UPDATE mainimage in the apartments table with the image list foreach apartment ID, hence the first row in the list foreach apartment ID Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271710 Share on other sites More sharing options...
Muddy_Funster Posted September 22, 2011 Share Posted September 22, 2011 is there a field in the images table that refferences the appartment table to show which apartment the image is of? Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271712 Share on other sites More sharing options...
dflow Posted September 22, 2011 Author Share Posted September 22, 2011 is there a field in the images table that refferences the appartment table to show which apartment the image is of? apartments.ID=images.ID Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271725 Share on other sites More sharing options...
fenway Posted September 22, 2011 Share Posted September 22, 2011 What are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271759 Share on other sites More sharing options...
requinix Posted September 22, 2011 Share Posted September 22, 2011 UPDATE apartments SET mainImage = (SELECT ImageURL FROM images WHERE images.ID = apartments.ID LIMIT 1) WHERE InternalSupplierID = 7 You could write the UPDATE to use a JOIN but I think MySQL will optimize the subquery into that form anyways. Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271793 Share on other sites More sharing options...
fenway Posted September 22, 2011 Share Posted September 22, 2011 Why are you running this query? Is this a one-off DB cleanup? Otherwise, don't store the same value in 2 places. Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271808 Share on other sites More sharing options...
dflow Posted September 22, 2011 Author Share Posted September 22, 2011 Why are you running this query? Is this a one-off DB cleanup? Otherwise, don't store the same value in 2 places. what do you mean? how would i call an apartment images list? Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271844 Share on other sites More sharing options...
requinix Posted September 22, 2011 Share Posted September 22, 2011 Why are you running this query? Is this a one-off DB cleanup? Otherwise, don't store the same value in 2 places. what do you mean? how would i call an apartment images list? I'll answer that with another question: How do you know what to set the mainImage to? Quote Link to comment https://forums.phpfreaks.com/topic/247641-update-distinct-with-id/#findComment-1271848 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.