Jump to content

mysql query


bugcoder

Recommended Posts

I have three columns table tbl_foods with sample data as follows

 

id food_id weight

1  1050 cup, tbsp

2  1050 oz

3  1053 tbsp

4  1058 cup

5  1058 cup,oz

6  1069 oz

7  1070 tbsp

8  1071 fluid

9  1078 tbsp

 

 

I want every food_id which does not have "oz" as weight should be inserted with new id in this table

e.g now 1053,1070,1071 and 1078 will be inserted with new ids and wights as "oz".

Link to comment
https://forums.phpfreaks.com/topic/206994-mysql-query/
Share on other sites

Assuming you are going to insert back into the same table, and the field "ID" is set as Primary Index, AutoIncrement, you can do the following

 

INSERT INTO 'food' (SELECT null as id, food_id, 'oz' as weight FROM `food` WHERE `weight` NOT LIKE '%oz%');

 

Or if you are wanting to modify those records, and not insert new ones, then

 

UPDATE food SET weight = 'oz' WHERE `weight` NOT LIKE '%oz%');

Link to comment
https://forums.phpfreaks.com/topic/206994-mysql-query/#findComment-1082441
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.