Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
getur.srikanth@gmail.com
Yak Posting Veteran
77 Posts |
Posted - 2010-07-29 : 10:15:07
|
I have a table having duplicate records. Columns are same except 2 columns. Please below example How can I write query for this? thanks in advance for your help. |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-07-29 : 10:28:20
|
| Hello,For example:Query 1:SELECTTitle,Section,PTDFROM A _aWHERE (select count(*) from A where Title=_a.Title and PTD=_a.PTD)>1;Query 2:SELECTTitle,Section,PTDFROM A _aWHERE (select count(*) from A where Title=_a.Title and Section=_a.Section)>1;Best regards,Devart Team |
 |
|
|
Celko
Starting Member
23 Posts |
Posted - 2010-07-29 : 13:53:05
|
quote: Originally posted by getur.srikanth@gmail.com I have a table having duplicate records [sic: rows are not records]. Columns are same except 2 columns. Please below example How can I write query for this? thanks in advance for your help.
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. If you know how, follow ISO-11179 data element naming conventions and formatting rules. Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. Sample data is also a good idea, along with clear specifications. It is very hard to debug code when you do not let us see it. If you want to learn how to ask a question on a Newsgroup, look at: http://www.catb.org/~esr/faqs/smart-questions.html SELECT vague_id, job_title, MIN(section_name), ptd FROM TableA GROUP BY vague_id, job_title, ptdHAVING COUNT(*) > 1;SELECT vague_id, job_title, section_name, ptd FROM TableA GROUP BY vague_id, job_title, section_name, ptdHAVING COUNT(vague_id) > 1;Author ofSQL for Smarties Thinking in SetsSQL Puzzles and AnswersAnalytics and OLAP in SQLSQL Programming Style Standards in SQLData & DatabasesTrees & Hierarchies in SQL |
 |
|
|
|
|
|
|
|