简体   繁体   中英

WHERE condition with multiple tables

I'm deleting table content that matches username in all four tables..ie..if i delete one record of username 'user1' from 1st table..it should delete the record in all the tables where username is 'AAA'.

the tables i use is

table 1 : p_user_profile

p_id        username  
----        --------
1           AAA

table 2 : p_device_id

d_id        username 
----        --------
1           AAA

table 3 : p_temp_notification

p_id        username   type
----        --------   -----
1           AAA          i

table 4 : p_sent_notification

p_id        username   type
----        --------   -----
1           AAA          i

here i want to delete the records that matches the username from all tables and match with of type="i" from 3 & 4 tables.

below is the code i used :

$p_id = intval($_REQUEST['p_id']);
include 'db/connection.php';
$sql= "DELETE p_user_profile, p_device_id, p_sent_notification FROM p_user_profile LEFT JOIN p_device_id ON p_device_id.username = p_user_profile.username
                                                                                   LEFT JOIN p_sent_notification ON p_device_id.username = p_sent_notification.username WHERE p_id = $p_id AND p_sent_notification.type = "i" ";

In the ablove query, if i execute with one WHERE condition it is successfully executing..but it is deleting type of all records..but i want to delete records of only type="i"..

Plz help in resolving..Thankyou

您在查询中使用p_sent_notification ,而表名为send_notification

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