Hi,
Being new to DB2 I'm having a small problem that I'm sure is quite easy to someone smarter than me.
I have a table with duplicate entries and I need to know how to code a query to exctract certain fields from the table with a count > 1. I can do this with one field however I need to do this with multiple fields.
Working 1 Field Query, - select field_3 from CUSTOMER where field_3 <> ' ' group by field_3 having count(*) > 1
What doesn't work, - select * from CUSTOMER where field_3 <> ' ' group by field_3 having count(*) > 1
Table Name: CUSTOMER
# of Fields: 5 (e.g. Filed_1, Field_2, Field_3, etc)
If some could help me with this I would be eternally grateful.
Thanks in advance.......
2 1247
Provided you are on V8.1 or later, try the following: - create table test(col1 char(3),
-
col2 char(3),
-
col3 char(3));
-
-
insert into test values ('1A','1B','1C');
-
insert into test values ('2A','2B','2C');
-
insert into test values ('3A','3B','3C');
-
insert into test values ('3A','3B','3C');
-
insert into test values ('3A','3B','3C');
-
insert into test values ('4A','4B','4C');
-
insert into test values ('5A','5B','5C');
-
insert into test values ('5A','5B','5C');
-
-
with x(rnum, col1, col2, col3) as (select rownumber() over(order by col1, col2, col3),
-
col1,
-
col2,
-
col3
-
from test)
-
select distinct x1.col1,
-
x1.col2,
-
x1.col3
-
from x x1,
-
x x2
-
where x1.col1 = x2.col1
-
and x1.col2 = x2.col2
-
and x1.col3 = x2.col3
-
and x1.rnum <> x2.rnum
Thinking some more on this, there is a much simpler way: - select distinct col1,
-
col2,
-
col3
-
from test
-
group by col1,
-
col2,
-
col3
-
having count(*) > 1
Sign in to post your reply or Sign up for a free account.
Similar topics
by: James Turner |
last post by:
I am trying to store formatted text (windows format) into a MySQL
database and then retrieve it. The field in the database is a
varchar. I cut and paste the test into a form field formatted, then...
|
by: Newbee |
last post by:
Hi !
Let's say that this is the folder on the server:
/web/firstDir/secondDir/images/image.gif
where i have stored my pictures. I have tryed with apsolute and relative
paths but i can't display...
|
by: Newbee Adam |
last post by:
some said that .NET app can run on any program where rutime exists. What is
"runtime" in this sense?
will I have to install runtime or .net framework or .NET support on an xp
machine for a...
|
by: Magnus |
last post by:
Hi,
I have previously worked mostly with Sql Server and wonder how to write
a subselect query in mysql 4.0. What i would like to do is something
like:
select a.name, b.isbn
from author a...
|
by: PerryC |
last post by:
All,
1. Do the following codes seem ok?
2. If so, then how do I pull the value of YOE1 and YOE2 into my
report? (to do some further calculations)
...
|
by: Martin Hvidberg |
last post by:
Dear list
I have found a declaration like this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "ectemp.h"
|
by: tony |
last post by:
Hello,
I am trying to loop through a collection of objects, create a sql
string
from data held within those objects and insert into a database.
Each time through the loop the program seems to...
|
by: ikarias |
last post by:
Maybe not the right place to aske this, but a newbee (me) needs help.
i trying to input a number into a textbox, so i can make a series of calculations. in the old days of basic i just jused...
|
by: Rene |
last post by:
Hello to all!
I am a newbee to C++, I did a beginners' course, and now I am stuck with a
strange problem.
I have written the function that is pasted downwards. The peculiar thing is
that when...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |