A SQL statement that filters duplicate data _mssql

Source: Internet
Author: User
The data are as follows:

303 Standard Category Tr_standard_manager
107 Patrol Record category Tr_patrol_log
61 Patrol record Category Tr_patrol_log
221 Repair Type Tr_repair_log
121 Maintenance Management Plan category Tr_repair_plan
141 Maintenance Management Plan category Tr_repair_plan
24 Equipment Management Category Tr_patrol_plan_1
105 Patrol Plan Category Tr_patrol_plan
108 Maintenance Management Plan category Tr_repair_plan
109 Repair Type Tr_repair_log
1 Patrol Plan category Tr_patrol_plan
2 Patrol record category Tr_patrol_log
26 Equipment Management Category Tr_patrol_plan_1
142 Repair Type Tr_repair_log
145 Accident Type Tr_accident
144 Accident Type Tr_accident
261 Patrol Plan category Tr_patrol_plan
147 Load Type Tr_burthen
262 Patrol plan category Tr_patrol_plan
265 Patrol Plan category Tr_patrol_plan
267 Maintenance Management Plan category Tr_repair_plan
268 Maintenance Management Plan category Tr_repair_plan
269 Accident Type Tr_accident
146 Accident Type Tr_accident
283 Standard category Tr_standard_manager
263 Patrol Plan Category Tr_patrol_plan
5 Information Category Tr_equp_att_info
266 Maintenance Management Plan category Tr_repair_plan
281 Information Category Tr_equp_att_info

//////////////////////////////////////////

You need to obtain a duplicate category name and a corresponding primary key ID.

Select Scop_name, run_type_id from Tr_type a where
Run_type_id= (SELECT MAX (run_type_id) from Tr_type b where A.scop_name =b.scop_name)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.