去重

比如说有一个表,字段id(自增主键),book_id,line_num记录某本书看到某一行,
id book_id line_num
1 123 110
2 123 110
3 222 111
4 311 322
5 311 322
6 311 322
去除重复数据,sql如下:

""" DELETE
FROM
test3
WHERE
id NOT IN (
SELECT
a.id
FROM
(
SELECT
min(id) AS id
FROM
test3
GROUP BY
book_id,
line_num
HAVING
count(*) > 1
) a
)
"""

两个子查询是为了避免You can't specify target table 'test3' for update in FROM clause 错误

DDL DML

Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:
CREATE - to create objects in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
COMMENT - add comments to the data dictionary
RENAME - rename an object

Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:
SELECT - retrieve data from the a database
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the space for the records remain
MERGE - UPSERT operation (insert or update)
CALL - call a PL/SQL or Java subprogram
EXPLAIN PLAN - explain access path to data
LOCK TABLE - control concurrency

http://www.orafaq.com/faq/what_are_the_difference_between_ddl_dml_and_dcl_commands

posted on 2015-06-30 14:44  onesteng  阅读(118)  评论(0编辑  收藏  举报