473,748 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with an WHERE NOT EXISTS subquery please.

Hi, I have 2 tables:

tblStations StationID
Station

tblStationUser RecordID
UserName
Station

I'm trying to come up with a dataset that contains the
tblStations.Sta tion
EXCEPT for where that Station exists in tblStationUser where the
UserName = @varUserName.

I've tried this but get 0 rows (I should get about 40):

SELECT tblStations.Sta tion
FROM tblStations
WHERE NOT EXISTS
(SELECT tblStationUser. Station FROM tblStationUser WHERE
tblStationUser. UserName=@varUs erName)
ORDER BY Station

I tried the subquery separately which returns the correct number of
rows.

Any clues as to where I'm going wrong?

Thanks!
Kathy
Jul 20 '05 #1
3 37160
Kathy,

You forgot to join tables. Try one of these queries. I haven't tested them.

SELECT Station
FROM tblStations
WHERE NOT EXISTS (SELECT *
FROM tblStationUser
WHERE tblStationUser. Station = tblStations.Sta tion
AND tblStationUser. UserName = @varUserName)
ORDER BY Station

OR

SELECT Station
FROM tblStations
WHERE Station NOT IN (SELECT Station
FROM tblStationUser
WHERE UserName = @varUserName)
ORDER BY Station

Good luck,
Shervin

"KathyB" <Ka**********@a ttbi.com> wrote in message
news:75******** *************** ***@posting.goo gle.com...
Hi, I have 2 tables:

tblStations StationID
Station

tblStationUser RecordID
UserName
Station

I'm trying to come up with a dataset that contains the
tblStations.Sta tion
EXCEPT for where that Station exists in tblStationUser where the
UserName = @varUserName.

I've tried this but get 0 rows (I should get about 40):

SELECT tblStations.Sta tion
FROM tblStations
WHERE NOT EXISTS
(SELECT tblStationUser. Station FROM tblStationUser WHERE
tblStationUser. UserName=@varUs erName)
ORDER BY Station

I tried the subquery separately which returns the correct number of
rows.

Any clues as to where I'm going wrong?

Thanks!
Kathy

Jul 20 '05 #2
Thanks again Shervin. I wish I knew I fraction of what you do!
Thanks, Kat

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
You are welcome Kathy, I'm hanging around here to learn more about SQL
Server. :-)

Shervin

"Kathy Burke" <ka**********@c omcast.net> wrote in message
news:3f******** *************@n ews.frii.net...
Thanks again Shervin. I wish I knew I fraction of what you do!
Thanks, Kat

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #4

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

Similar topics

7
3615
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
4
1530
by: kirill_uk | last post by:
Help with extracting please folks.! Hi. I have this: a variable like: <a href="http://www.some_html.com/text.html" >some text</a><br> I heed to extract the "http://www.some_html.com/text.html " and put it in var "link" And extract "some text" and put it var "text",. So basically extract all between <a href=" and " >
4
1400
by: David | last post by:
Hi, Please can you help me get this code to run ? -------------------- Dim dbs2 As DAO.Database, rst2 As DAO.Recordset, str2 As String Set dbs2 = CurrentDb strtest2 = "SELECT products.ProdCode, products.ProductIdentify FROM
0
1282
by: vinod babu via .NET 247 | last post by:
(Type your message here) -------------------------------- From: vinod babu Here my adding a new row code Private Sub cmdadd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd1.Click If DataExists() = False Then Exit Sub MaintenancereportDataSet = DataRetrieve()
1
2239
by: hik2sanity | last post by:
I have a table that records targets and the time it appears on a display. What I would like to do is to report the time difference for each individual target from the initial appearance to the subsequent one, and the time difference from the subsequent one to the next, and so on. So how do I put these these all together to produce one query: for each "select distinct target from display" for number of rows -1 with target
3
1312
by: MrHelpMe | last post by:
Hello experts and thanks so much for having a look at this. I have the following peice of code that I am stumped on. <table width="90%" cellpadding=0 align="center"> <tr> <td align="left"><font face="arial,helvetica" size=4 Color = "8CB811"><b><%= Trim(objRS("Category")) %></b></font></td> </tr> <%
1
1072
by: sqlDon | last post by:
I am looking for some suggestions for rewriting a subquery to be more efficient. Select * from A where A.col1+A.col2 in (Select A.col1+A.col2 from A where A.Col3 = 'TEST1' and A.Col4 = 'TEST2') The above works, but is slow. I know this can probably be written using a JOIN to be more efficient, but everything I am trying is not returning what I want. Thanks
1
2358
by: mnymoen | last post by:
I have tried 2 variations of this query and cannot get it to work due to the fact I cant use "where email in". I get this error "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS". I am trying to import records from the marketingmaster table that allows duplicate entries in the email column to the addresses table that has the email column as the primary key. If I run the bottom half, I...
3
1549
by: ncsthbell | last post by:
Here is currently what I have coded: Update HWInv set ReconFAS = True, DateFAS = Date() where exists (SELECT asset_number FROM tbl_FASRecon WHERE Verified_By = "IT Recon" ) My problem is that when I run the select statement by itself it returns 5821 rows. Then, I put the "Update" in front of it and it updates 6323 rows. The 5821 rows is actually what should be updated. I can't figure out what I have wrong. Basically, I want to update...
0
8995
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
8832
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
9558
Oralloy
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...
0
9378
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
9331
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
9253
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
6798
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
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.