1

my tables: blocked_peoples and members. In table blocked_peoples column ips = members column signup_ip.

Let's say i wanna block person from accessing my site. I block user by his IP and it too update members table and column banned with 1.

In short, if i update table blocked_peoples (column ips) and it's result found/same as members (column signup_ip) in members table update column banned with 1.

It's possible ? If yes, how sql will look like ?

3 Answers 3

1
UPDATE blocked_peoples, members
   SET members.banned = 1 
 WHERE members.signup_ip = blocked_peoples.ip 
   AND blocked_peoples.ip = 'ip.address.goes.here';

That's the best I can come up with based on your question. I'm not sure though. It doesn't make sense to use two tables in the update since members table has both the ip and the "blocked" flag.

Sign up to request clarification or add additional context in comments.

Comments

0

STEPS:

  • first make both table engine to INNODB
  • then create a foreign key reference with constraint ON UPDATE CASCADE ON DELETE CASCADE
  • parent_table(blocked_people).ips will be referenced to child table(members).signup_ip

for more information read about foreign key reference .

Happy To HELP :)

2 Comments

InnoDB requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan.
0

I would recommend getting rid of the blocked_peoples table completely if the relationship to members is 1-to-1. Otherwise, you should remove the banned column from members and rely specifically on the blocked_peoples to check for banned IPs.

Example Update:

UPDATE `members` SET `banned` = 1 WHERE `signup_Ip` = '123.123.123.123';

Example Select:

SELECT * FROM `members` WHERE `banned` = 1 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.