简体   繁体   中英

PDO sql delete with multiple conditions

This is what I tried:

$query="DELETE FROM network_friend WHERE friend_request = :usrfriend AND friend = :isfriend UNION DELETE FROM network_friend WHERE friend_request = :friend_request AND friend = :friendisfriend";

I have the column structure

D b

same structure instead of

friend1 friend2 friend1

could be like

friend2 friend1 friend2 

How to delete case if columns: friend_request OR friend_is_friend Is the same user and friend column is the user I want to delete?

something like "DELETE FROM table WHERE friend = :user1 AND friend_request = :user2 AND friend_is_friend = :user2"

or also the inverse

"DELETE FROM table WHERE friend = :user2 AND friend_request = :user1 AND friend_is_friend = :user1"

The problem is i need delete case user1 = friend_request and user1 friend_is_friend AND ALSO friend = user2 the inverse could also be in the place of user 1 user 2 and in the place of user 2 user 1

How to delete with multiple conditions and make this into single statement?

I think you want:

DELETE nf FROM network_friend nf
    WHERE (friend_request = :usrfriend AND friend = :isfriend) OR
          (friend_request = :friend_request AND friend = :friendisfriend)

我觉得是=D

$sql = 'DELETE FROM network_friend WHERE friend_request = friend_is_friend AND friend = :user_you_want_to_delete';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM