MySQL 删除-Select 行
MySQL Delete-Select row
我正在尝试从 table subscription 中删除一行,其中有两个外键 (id_user 和 id_journal)。我的信息是 email 来自 table user 和 nome 来自 table 期刊。删除的行需要匹配user.email和journal.nome。我找不到解决办法。我该怎么做?
Table 用户:
id
name
email
password
Table 期刊:
id
name
Table 订阅:
id
id_user
id_journal
我尝试的最后两个查询:
DELETE FROM assinatura WHERE (
SELECT tbluser.id, journal.id
FROM tbluser, journal
WHERE email = '$email' AND nome = '$nome')
DELETE FROM assinatura
INNER JOIN tbluser on (tbluser.email = '$email')
INNER JOIN journal on (journal.nome = '$nome')
我尝试了很多其他查询,但都没有成功。我认为重要的是要说我是 MySQL.
的新人
DELETE
FROM Subscription
WHERE id_user IN (
SELECT usr.id
FROM user AS usr
WHERE usr.email = INPUT_EMAIL
)
AND id_journal IN (
SELECT jrnl.id
FROM journal AS jrnl
WHERE jrnl.name = INPUT_NAME
)
关于另一个话题...
尽量避免
对相同user/journal组合的过度订阅
CREATE TABLE subscription
(
id int NOT NULL AUTO_INCREMENT primary key,
id_user int not null,
id_journal int not null,
UNIQUE KEY `user_journal_intersect` (`id_user`,`id_journal`)
-- note Alan stated FK RI in place already
);
你当然可以在复合材料上进行 PK(放弃 id
列),程序员偏好
我正在尝试从 table subscription 中删除一行,其中有两个外键 (id_user 和 id_journal)。我的信息是 email 来自 table user 和 nome 来自 table 期刊。删除的行需要匹配user.email和journal.nome。我找不到解决办法。我该怎么做?
Table 用户:
id
name
email
password
Table 期刊:
id
name
Table 订阅:
id
id_user
id_journal
我尝试的最后两个查询:
DELETE FROM assinatura WHERE (
SELECT tbluser.id, journal.id
FROM tbluser, journal
WHERE email = '$email' AND nome = '$nome')
DELETE FROM assinatura
INNER JOIN tbluser on (tbluser.email = '$email')
INNER JOIN journal on (journal.nome = '$nome')
我尝试了很多其他查询,但都没有成功。我认为重要的是要说我是 MySQL.
的新人DELETE
FROM Subscription
WHERE id_user IN (
SELECT usr.id
FROM user AS usr
WHERE usr.email = INPUT_EMAIL
)
AND id_journal IN (
SELECT jrnl.id
FROM journal AS jrnl
WHERE jrnl.name = INPUT_NAME
)
关于另一个话题...
尽量避免
对相同user/journal组合的过度订阅CREATE TABLE subscription
(
id int NOT NULL AUTO_INCREMENT primary key,
id_user int not null,
id_journal int not null,
UNIQUE KEY `user_journal_intersect` (`id_user`,`id_journal`)
-- note Alan stated FK RI in place already
);
你当然可以在复合材料上进行 PK(放弃 id
列),程序员偏好