Home > Database > Mysql Tutorial > body text

SQL statement to remove duplicate records and obtain duplicate record example code

怪我咯
Release: 2018-05-28 17:18:11
Original
1677 people have browsed it

SQL statement to remove duplicate records and obtain duplicate records
--QueryEffectively remove duplicate records in a table, UserID is an auto-increasing primary key, and RoleID is a repeated field

SELECT MIN(UserID) AS UserID, RoleID FROM tmpTable GROUP BY RoleID 

SELECT RoleID FROM tmpTable GROUP BY RoleID HAVING (COUNT(*) > 1) 

SELECT DISTINCT * FROM tmpTable
Copy after login

sql statement query all table names and field names in the sql server access database February 01, 2007 Thursday 04:21 PMSQL SERVER
View all table names:

select   name   from   sysobjects   where   type='U'
Copy after login

Query table All field names:

Select name from syscolumns Where ID=OBJECT_ID('表名') 

select * from information_schema.tables 
select * from information_schema.views 
select * from information_schema.columns
Copy after login

ACCESS
View all table names:

select   name   from   MSysObjects   where   type=1   and   flags=0
Copy after login

MSysObjects are system objects, which are hidden by default . It can be displayed through tools, options, view, display, and system objects

The above is the detailed content of SQL statement to remove duplicate records and obtain duplicate record example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template