Does anyone have any recommendations on how to solve the following?
I would like to have a query that selects ALL columns from a database,
however only records that have a count of a certain column which is
greater than 1 when the results are grouped by a few columns. I know
the following query doesnt work (because it contains items in the
SELECT that arent in the GROUP BY), but its the jist of what I need to
do.
select a,b,c,d,e,f,g,h
from table1
group by a,b,c,d
having count(e) > 1
Can anyone help me out with this? 3 16582
Below is just a guess because your spec isn't very precise. The
following article explains the best way to get help with this sort of
problem: http://www.aspfaq.com/etiquett*e.asp?id=5006
Meanwhile, try this:
SELECT a,b,c,d,e,f,g,h
FROM Table1 AS T
WHERE EXISTS
(SELECT *
FROM Table1
WHERE a = T.a
AND b = T.b
AND c = T.c
AND d = T.d
AND e <> T.e)
--
David Portas
SQL Server MVP
--
Thanks for your speedy response. Sorry I was unclear in my question.
Hopefully the sample data will help with my explanation.
example data from table (the real table has 300K records)
a b c d e f g, h......
abcd 547 90 206 19126 02385
abce 547 90 207 19127 9872349
abce 547 90 207 79823 78923075
abce 547 90 207 79823 79872309
abce 547 90 207 79823 89723534
abce 547 90 208 79823 72983454
abce 547 90 208 77834 89052256
abcf 548 91 208 77834 89437545
desired results
abce 547 90 207 79823 78923075
abce 547 90 207 79823 79872309
abce 547 90 207 79823 89723534
In case anyone else is looking for a similar sulution, a user from
another forum posted this answer which helped me out greatly.
select a.* from <tablename> a join
(select col_a,col_b,col_c,col_d,col_e,count(*) dup_count from
<tablename>
group by col_a,col_b,col_c,col_d,col_e
having count(*)>1) b
on a.col_a=b.col_a and
a.col_b=b.col_b and
a.col_c=b.col_c and
a.col_d=b.col_d and
a.col_e=b.col_e This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro...
|
by: Tuang |
last post by:
I'm checking out Python as a candidate for replacing Perl as my "Swiss
Army knife" tool. The longer I can remember the syntax for performing
a task, the more likely I am to use it on the spot if...
|
by: shank |
last post by:
1) I'm getting this error: Syntax error (missing operator) in query
expression on the below statement. Can I get some advice.
2) I searched ASPFAQ and came up blank. Where can find the "rules"...
|
by: Robby McGehee |
last post by:
I need this to work:
SELECT FROM WITH (NOLOCK) where ='a' GROUP BY , HAVING COUNT () > 1
The problem is that I get an error that needs to be in the GROUP
BY clause or aggregate function. if...
|
by: Paxton |
last post by:
Hi,
I'm trying to display the total page views per page within a given date
range, but the correct SQL is seemingly beyond me. I get the correct result
with a straightforward Group By and Count...
| |
by: Chris Kettenbach |
last post by:
Hi Peter,
I get error when processing the stylesheet. It errors here.
<xsl:for-each select="registration)=1]">
specifically:
Expression does not return a DOM node.
registration)=1]<--
|
by: Anne Heddal |
last post by:
In the first line I'm trying to count the the unqiue values of the ID
column, but I'm getting syntax error, any idea how to format the distinct
count?
SELECT Count(test.ID) AS IDCOUNT FROM...
|
by: Sandesh |
last post by:
Hello All,
Me saying " has any body come across such error would be
underestimating".
Well I am getting a very peculiar and unique error "Line 1: Incorrect
syntax near 'Actions'."
...
|
by: DBDriver |
last post by:
I have an Access 97 database on WinXP with a linked Excel table of about
100,000 rows.
I'm trying to construct a query that will give me an editable datasheet
showing records where data in a pair...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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: 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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |