shage Posted June 10, 2008 Share Posted June 10, 2008 I have a database that is forever old that was one of the first things i ever did, the db has close to 5k records in it, is there a way to pull only say every record that ends in 1 or 2 for the id, such as 101 and 1001, the way the db is set up every 1 is shoes, every 2 is tvs, every 3 is toys etc, but they have no cats so looking to add a cat to them buy running a query and adding all 3's are in cat toys, thank you Link to comment https://forums.phpfreaks.com/topic/109578-mysql-question/ Share on other sites More sharing options...
luca200 Posted June 10, 2008 Share Posted June 10, 2008 UPDATE table SET cat = 'shoes' WHERE id % 10 = 1 UPDATE table SET cat = 'tvs' WHERE id % 10 = 2 UPDATE table SET cat = 'toys' WHERE id % 10 = 3 Link to comment https://forums.phpfreaks.com/topic/109578-mysql-question/#findComment-562215 Share on other sites More sharing options...
fenway Posted June 10, 2008 Share Posted June 10, 2008 Or you could use a CASE statement and issue a single udpate: UPDATE table SET cat = CASE id % 10 WHEN 1 THEN 'shoes' WHEN 2 THEN 'tvs' WHEN 3 THEN 'toys' ELSE cat END Link to comment https://forums.phpfreaks.com/topic/109578-mysql-question/#findComment-562404 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.