mysql trigger after insert with 3 tables
up vote
0
down vote
favorite
I have 3 tables: the first one gets all records to the t1 table, the second one is where my whitelist entries are, and the third one is for making some decision in the future regarding to t2.
I need to create after insert trigger an update via my third table.
the steps :
- some value come into the tables called "t1"
- need to check if the value is in "t2"
- if the value is in t2 so go to t3 and do something, if the value is not in t2 so go to t3 and do something else.
- but the value will always need to enter t1.
This is my code and it does not work, I don't know how to apply it I've tried many options already.
CREATE TRIGGER check_whitelist AFTER INSERT ON t1
FOR EACH ROW
SELECT
IF(IFNULL(new.name=(
select name From t2 where (t2.name = new.name),
UPDATE t3 SET option1 =0 ,
UPDATE t3 SET option2 =1
)))
Please help me with writing this code.
mysql
New contributor
add a comment |
up vote
0
down vote
favorite
I have 3 tables: the first one gets all records to the t1 table, the second one is where my whitelist entries are, and the third one is for making some decision in the future regarding to t2.
I need to create after insert trigger an update via my third table.
the steps :
- some value come into the tables called "t1"
- need to check if the value is in "t2"
- if the value is in t2 so go to t3 and do something, if the value is not in t2 so go to t3 and do something else.
- but the value will always need to enter t1.
This is my code and it does not work, I don't know how to apply it I've tried many options already.
CREATE TRIGGER check_whitelist AFTER INSERT ON t1
FOR EACH ROW
SELECT
IF(IFNULL(new.name=(
select name From t2 where (t2.name = new.name),
UPDATE t3 SET option1 =0 ,
UPDATE t3 SET option2 =1
)))
Please help me with writing this code.
mysql
New contributor
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have 3 tables: the first one gets all records to the t1 table, the second one is where my whitelist entries are, and the third one is for making some decision in the future regarding to t2.
I need to create after insert trigger an update via my third table.
the steps :
- some value come into the tables called "t1"
- need to check if the value is in "t2"
- if the value is in t2 so go to t3 and do something, if the value is not in t2 so go to t3 and do something else.
- but the value will always need to enter t1.
This is my code and it does not work, I don't know how to apply it I've tried many options already.
CREATE TRIGGER check_whitelist AFTER INSERT ON t1
FOR EACH ROW
SELECT
IF(IFNULL(new.name=(
select name From t2 where (t2.name = new.name),
UPDATE t3 SET option1 =0 ,
UPDATE t3 SET option2 =1
)))
Please help me with writing this code.
mysql
New contributor
I have 3 tables: the first one gets all records to the t1 table, the second one is where my whitelist entries are, and the third one is for making some decision in the future regarding to t2.
I need to create after insert trigger an update via my third table.
the steps :
- some value come into the tables called "t1"
- need to check if the value is in "t2"
- if the value is in t2 so go to t3 and do something, if the value is not in t2 so go to t3 and do something else.
- but the value will always need to enter t1.
This is my code and it does not work, I don't know how to apply it I've tried many options already.
CREATE TRIGGER check_whitelist AFTER INSERT ON t1
FOR EACH ROW
SELECT
IF(IFNULL(new.name=(
select name From t2 where (t2.name = new.name),
UPDATE t3 SET option1 =0 ,
UPDATE t3 SET option2 =1
)))
Please help me with writing this code.
mysql
mysql
New contributor
New contributor
edited yesterday
Yoram de Langen
3,82611524
3,82611524
New contributor
asked yesterday
a.artur
12
12
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
You can't put an UPDATE
query inside a SELECT
query. Use an IF()
expression in the value that you're assigning to option1
.
FOR EACH ROW
UPDATE t3 SET option1 = IF(new.name = (SELECT name FROM t2 WHERE t2.plate = new.name),
0, 1)
thank you very much its work for me.
– a.artur
yesterday
@a.artur Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
14 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You can't put an UPDATE
query inside a SELECT
query. Use an IF()
expression in the value that you're assigning to option1
.
FOR EACH ROW
UPDATE t3 SET option1 = IF(new.name = (SELECT name FROM t2 WHERE t2.plate = new.name),
0, 1)
thank you very much its work for me.
– a.artur
yesterday
@a.artur Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
14 hours ago
add a comment |
up vote
1
down vote
You can't put an UPDATE
query inside a SELECT
query. Use an IF()
expression in the value that you're assigning to option1
.
FOR EACH ROW
UPDATE t3 SET option1 = IF(new.name = (SELECT name FROM t2 WHERE t2.plate = new.name),
0, 1)
thank you very much its work for me.
– a.artur
yesterday
@a.artur Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
14 hours ago
add a comment |
up vote
1
down vote
up vote
1
down vote
You can't put an UPDATE
query inside a SELECT
query. Use an IF()
expression in the value that you're assigning to option1
.
FOR EACH ROW
UPDATE t3 SET option1 = IF(new.name = (SELECT name FROM t2 WHERE t2.plate = new.name),
0, 1)
You can't put an UPDATE
query inside a SELECT
query. Use an IF()
expression in the value that you're assigning to option1
.
FOR EACH ROW
UPDATE t3 SET option1 = IF(new.name = (SELECT name FROM t2 WHERE t2.plate = new.name),
0, 1)
answered yesterday
Barmar
413k34237339
413k34237339
thank you very much its work for me.
– a.artur
yesterday
@a.artur Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
14 hours ago
add a comment |
thank you very much its work for me.
– a.artur
yesterday
@a.artur Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
14 hours ago
thank you very much its work for me.
– a.artur
yesterday
thank you very much its work for me.
– a.artur
yesterday
@a.artur Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
14 hours ago
@a.artur Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
– Madhur Bhaiya
14 hours ago
add a comment |
a.artur is a new contributor. Be nice, and check out our Code of Conduct.
a.artur is a new contributor. Be nice, and check out our Code of Conduct.
a.artur is a new contributor. Be nice, and check out our Code of Conduct.
a.artur is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372160%2fmysql-trigger-after-insert-with-3-tables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown