473,811 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select row with only ONE occurence

das
Hi all,
How can I get a row that has only one occurence in a table? Not
through 'distinct' because this gets a single row that might have
multiple occurences, I want to get only rows that have only one
occurence in the table.

I tried the group by and within the having clause I placed the
count(myfield) = 1, did not work...
select f1, f2, count(f2)
from table1
inner join table2 on table1.id = table2.fid
where .....
group by f1, f2
having count(f2) = 1

gives me result like this: (basically in this situation, I dont want to
return any results)

f1 f2 count(f1)
--- --- -----------
1 a 1
2 a 1

any ideas sql gurus?

thanks

Mar 1 '06 #1
3 9294
an untested stab in the dark:

select f1, f2 from table1 join
(select f2, count(*) from table1 group by f2 having count(*)=1) t2
on t2.f2=table1.f2

Mar 1 '06 #2
The reason you are getting both rows back is because f1 is not
identical in each. You need to remove f1 from the group by and add an
aggregator to the select list.

Something like this:

select max(f1), f2
from table1
inner join table2 on table1.id = table2.fid
where .....
group by f2
having count(f2) = 1

Mar 2 '06 #3
das
That is correct, my grouping was wrong.

I will now enclose the inner sql in another one and get the value of
f1.

select f1, f2 from
(.....)

thanks!

Mar 2 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1440
by: nasht | last post by:
Hi, Interesting question: A user fills a form about how often an event happen. He has 4 fields: . In any of them, he can enter "*" as a joker, to say it doesn't matter. For example, his birthday is every October 5th, so he enters: , because the day of the week, or the year don't matter.
20
1639
by: truetype | last post by:
Greetings! I consider to create an application using .NET Framework. It would be used by any kind user, mostly those who do not know anyting about programming and ..NET Framework. But have some hesitations about .NET Framework occurence on computers of such users. Is there any statistics regarding this problem? I'm intrested mostly in statistics for USA and European Union.
17
5034
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by cust_no, ded_type_cd, chk_no)
0
2302
by: bonzo | last post by:
Hi everybody DB2 UDB V7.2 fp 9 is running on Win2K server. Database tablespaces are all SMS. Application is running on the same server and connected to database through ODBC. The first sign of problem in db2diag log is this: ===================================================
10
5318
by: Sean Berry | last post by:
I need to find the second to last occurence of a "." in a string. Basically I am taking a URL like http://this.is.mydomin.com/path/to/file.txt and want to extract /path/to/file.txt I thought I would be able to do it like this: ----------------------------------------------------
6
1564
by: utab | last post by:
Dear all, I would like to find the occurence of numbers in an array(I solved this problem before now I could not see the solution) but not with iterators or vectors I want to apply them later, I tried sth like this #include <iostream> #include <string> #include <vector>
3
1732
by: utab | last post by:
Dear all, I tried to solve the occurence problem: to find the distinct occurences of a word in an input. I know that I could use map and other STD lib functions. I tried to do it the hard way. I tried sth and it is working but I could not structure my algorithm very well so I had to add some more lines after thinking it on a paper draft. I am posting the whole code and waiting different ideas. First I sorted them with the sort function,...
2
2416
by: gauravguleria | last post by:
wht's the program which takes two strings using command line arguments and finds the occurence of second string in the first string.The program should return the starting position of first occurence if it is available otherwise should display "NOT FOUND".
1
1359
by: mustafalp | last post by:
i want to write it with following prototype: int occurence (int a,intasize,int e) this function must returns the number of occurence of e in the array a in c++.
0
9734
marktang
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...
0
9607
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,...
0
10397
jinu1996
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...
1
10410
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,...
0
10138
tracyyun
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...
1
7674
isladogs
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...
0
5564
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...
1
4353
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 we have to send another system
3
3027
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.