簡體   English   中英

有多個表的條件

[英]WHERE condition with multiple tables

我正在刪除與所有四個表中的用戶名都匹配的表內容。即,如果我從第一張表中刪除了一個用戶名“ user1”的記錄,則應刪除用戶名為“ AAA”的所有表中的記錄。

我用的桌子是

table 1 : p_user_profile

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

表2:p_device_id

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

表3:p_temp_notification

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

表4:p_sent_notification

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

在這里,我要刪除與所有表中的用戶名匹配並與3&4表中的類型為“ i”匹配的記錄。

以下是我使用的代碼:

$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" ";

在ablove查詢中,如果我以一個WHERE條件執行,則它成功執行..但它正在刪除所有記錄的類型..但我只想刪除type =“ i”的記錄。

請幫助解決..謝謝

您在查詢中使用p_sent_notification ,而表名為send_notification

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM