首页 > mysql中的主从表连接后更新的问题

mysql中的主从表连接后更新的问题

MySQL 5.6 Schema Setup:

CREATE TABLE ForgeRock (
    `id` INT,
    `productName` VARCHAR (7),
    `description` VARCHAR (55)
);

INSERT INTO ForgeRock (
    `id`,
    `productName`,
    `description`
)
VALUES
    (
        1,
        'OpenIDM',
        'Platform for building enterprise provisioning solutions'
    );
    
    CREATE TABLE ForgeRock_Detail (
        `detail_id` INT,
        `fr_id` INT,
        detail_description VARCHAR (55)
    );

INSERT INTO ForgeRock_Detail (
    detail_id,
    fr_id,
    detail_description
)
VALUES
    (1, 1, 'dd1'),
    (2, 1, 'dd2'),
    (3, 1, 'dd3');


Query 1:

select * from ForgeRock
left join ForgeRock_Detail
on id=fr_id

Results:

| id | productName |                                             description | detail_id | fr_id | detail_description |
|----|-------------|---------------------------------------------------------|-----------|-------|--------------------|
|  1 |     OpenIDM | Platform for building enterprise provisioning solutions |         1 |     1 |                dd1 |
|  1 |     OpenIDM | Platform for building enterprise provisioning solutions |         2 |     1 |                dd2 |
|  1 |     OpenIDM | Platform for building enterprise provisioning solutions |         3 |     1 |                dd3 |



就是一个mysql中的主从表,我现在想做的是连接后更新

UPDATE ForgeRock
LEFT JOIN ForgeRock_Detail ON id = fr_id
SET description = detail_description

现在的问题是,这条语句会不会执行三次对description的更新操作?

还有哦,这种语句有办法单步调试么?去看到底执行了几次操作。因为detail_description是不同的,如果description更新3个不同的值,应该是可以查到修改记录的。

【热门文章】
【热门文章】