我必须为特定记录添加一些行..我的项目正在运行..所以我不能重做整个数据库

I have to add one row for records where it is not present.. i cant empty/change database, beacause its on live..

for example:

id  |  attribute_id | val

28  |  11           | a  

28  |  12           | b

28  |  13           | c

28  |  14           | d

suppose this is one record in table of same id, this records are already present in table.. i have to add one row for old records where it is not present..

It should be added like this..

id  |  attribute_id | val

28  |  11           | a  

28  |  12           | b

28  |  13           | c

28  |  14           | d

28  |  15           | No

see the last row.. i have add attribute 15 for records(ids) where its not present

please suggest me mysql query to add this..

you would get all the ids in need of an insert by

SELECT id, SUM(attribute_id = 15)
FROM table
GROUP BY id
HAVING SUM(attribute_id = 15) = 0

I am nog sure Mysql will allow this in 1 query like

INSERT INTO table (id, attribute_id, val) 
SELECT id, 15 AS atr, 'NO' AS val
FROM table 
GROUP BY id, atr, val
HAVING SUM(attribute_id = 15) = 0

but try it

Else solve it using php by getting the ids from the first query and inserting afterwards. (Mysql is not always very allowing to read and write in the same table in one query)