Du kan använda en trigger:
CREATE TRIGGER biBooks
BEFORE INSERT ON books
FOR EACH ROW SET NEW.booknum = (
SELECT COALESCE(MAX(booknum), 0) + 1
FROM books
WHERE authors_id = NEW.authors_id
)
;
Du kan använda en trigger:
CREATE TRIGGER biBooks
BEFORE INSERT ON books
FOR EACH ROW SET NEW.booknum = (
SELECT COALESCE(MAX(booknum), 0) + 1
FROM books
WHERE authors_id = NEW.authors_id
)
;