Php 使用where子句删除行
我有一个桌名论坛, 这张桌子看起来像这样Php 使用where子句删除行,php,mysql,sql,sql-delete,Php,Mysql,Sql,Sql Delete,我有一个桌名论坛, 这张桌子看起来像这样 id studentid description teacherid 1 abc123 hi zxc123 2 abc123 hello qwe321 我想删除一行, 我试过的是 <?php require_once('Connections/dbcon.php'); mysql_select_db("school",
id studentid description teacherid
1 abc123 hi zxc123
2 abc123 hello qwe321
我想删除一行,
我试过的是
<?php
require_once('Connections/dbcon.php');
mysql_select_db("school", $dbcon);
$student_id=$_GET['student_id'];
$delete=mysql_query("DELETE from forum WHERE student_id='$student_id'")or die(mysql_error());
echo "<script language='Javascript'>alert('The Forum Successfully Deleted!');
location.href='tviewforum.php'</script>";
?>
我想在论坛上的具体信息。如果一个学生创建了两个论坛,我想删除其中一个,保留另一个。当一个学生创建了多个论坛时,您可以保留最大id 您可以使用group by,并且必须获得最大id并删除其他行
delete T from Table1 T
join ( select max(id) as id , studentid
from Table1
where studentid ='abc123'
group by studentid
having count(*) >1
) NewT
on T.id <> NewT.id
AND T.studentid = NewT.studentid
如果要删除forum表中的一行,请使用forum.id而不是forum.studentid。您能帮助我使用此查询进行查询吗?如果student表中有多个论坛,是否可能,我希望将所有这些都保留在我的数据库中。并在以后删除特定论坛