kevinkhan Posted November 16, 2010 Share Posted November 16, 2010 How do i complete this query i want the published column to go to 0 when all the published column is gone to one.. UPDATE Classified SET `published`=0 WHERE productid=2 AND Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/ Share on other sites More sharing options...
Adam Posted November 16, 2010 Share Posted November 16, 2010 You mean..? UPDATE Classified SET `published`=0 WHERE `published`=1 Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/#findComment-1134961 Share on other sites More sharing options...
kevinkhan Posted November 16, 2010 Author Share Posted November 16, 2010 You mean..? UPDATE Classified SET `published`=0 WHERE `published`=1 no sorry i only want to update when all entries are published = 1 like when count(published=0) = 0 Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/#findComment-1134975 Share on other sites More sharing options...
ManiacDan Posted November 16, 2010 Share Posted November 16, 2010 Wait, so you want ALL rows to set published=0 when NO rows are published=1? By virtue of binary logic, the database already does this. If no rows are published=1, and the only two values are 0 and 1, then all the rows are already zero. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/#findComment-1134993 Share on other sites More sharing options...
kevinkhan Posted November 16, 2010 Author Share Posted November 16, 2010 Wait, so you want ALL rows to set published=0 when NO rows are published=1? By virtue of binary logic, the database already does this. If no rows are published=1, and the only two values are 0 and 1, then all the rows are already zero. -Dan no i would like ALL rows to set published=0 when ALL rows are published=1? Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/#findComment-1134994 Share on other sites More sharing options...
ManiacDan Posted November 16, 2010 Share Posted November 16, 2010 You're going to have to do this in 2 queries. You could theoretically do it in one, but it would be easier to just select count(*) and SUM(published) and, if they match, do a global update statement. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/#findComment-1134998 Share on other sites More sharing options...
fenway Posted November 17, 2010 Share Posted November 17, 2010 I don't follow what's desired here. Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/#findComment-1135807 Share on other sites More sharing options...
ManiacDan Posted November 18, 2010 Share Posted November 18, 2010 I don't follow what's desired here. Once all articles are marked "published" he wants to "reset" the table so that they're all unpublished again. In English, "Update the table, set published = 1 where ALL ROWS are published = 0." I can see why you're confused. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/#findComment-1136066 Share on other sites More sharing options...
fenway Posted November 21, 2010 Share Posted November 21, 2010 Dare I ask why published becomes unpublished? Theoretically, this can be achieved with an UPDATE trigger -- but I don't think you can update the same table/record yet. Quote Link to comment https://forums.phpfreaks.com/topic/218830-looking-for-a-simple-sql-query/#findComment-1137523 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.