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 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 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 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 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? 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 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. 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 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. 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
Archived
This topic is now archived and is closed to further replies.