SQL的CRUD练习

sql示范:表名:course(课程)

SQL的CRUD练习_第1张图片

                           INSERT INTO TABLE VALUE (value1,value2)

添加(Create):insert into course value("8","地理","1")

                          SELECT column1,column2 FROM table

查询(Retrieve): select cid,cname,tid from course

                          UPDATE table SET column1 = value1 WHERE 条件

更新(Update):update course set  tid = 3 wher cname = "地理" 

                          DELETE FROM table WHERE column1 = value1

删除(Delete):delete from course where cid = "8"

 

 

1.删除数据库表中的重复数据只保留一条数据

delete from table
where tableName in (select * from ((SELECT tableName from table group by tableName having count(tableName) > 1 )a))  
and tableId not in (select * from ((select min(tableId) from table group by tableName having count(tableName) > 1)b))

 

你可能感兴趣的:(数据库,sql,java)