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 16595
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 capabilities, unfortunately. I'd like to know if it may
be possible to add a powerful macro system to Python, while
keeping its amazing syntax, and if it could be possible to
add Pythonistic syntax to Lisp or Scheme, while keeping all
of the...
|
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 the need arises.
If I have to go off and look it up, as I increasingly have to do with
Perl's ever hairier syntax, I'm more likely to just skip it, making me
even less likely to remember the syntax the next time.
So I hear that Python is easier...
|
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" for when
and how to use single quotes and double quotes in ASP?
thanks!
----------------------
SQL = SQL & "WHERE '" &
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE("GenKTitles.
|
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 I put it in there, I will get no
duplicates (because it is the identity field). The whole point of
this is to find dups.
Thanks for any help.
|
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 clause eg
SELECT DISTINCT tblPageViews.PageVisited,
Count(tblPageViews.PageVisited) AS CountOfPageVisited
FROM tblPageViews
GROUP BY tblPageViews.PageVisited;
| |
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 (select distinct test.ID FROM test),
Sum(test.balance) AS BAL, test.statement, billing.YYMM
FROM billing INNER JOIN test ON billing.ID = test.ID
WHERE (((test.invoice) Like "X*") AND ((test.due)=0) AND
((test.collections)=0))
GROUP BY test.statement,...
|
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'."
Explaining you the scene is the following Stored Proc.
|
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 of fields is duplicated.
As an example, I constructed this query on the Employees'table in the
Northwind Sample database. I appended four rows from the table back to the
table creating duplicates, then ran this SQL to locate rows where Firstname...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |