Answer the question
In order to leave comments, you need to log in
How to correctly compose a mysql query with a subquery to insert a new row?
Need to insert a new row into the table, but one of the row's values must be +1 to the maximum value of the "id_category" column in the specific user's table.
For example, if the table were not locked, then the query would be:
INSERT INTO category (
name,
id_user,
id_category,
created
) VALUES (
'новая категория',
1,
(SELECT MAX(id_category )+1
FROM category
WHERE id_user=1),
NOW()
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question