473,503 Members | 12,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Not Exist

I have a table called Elections where All is Yes/No

Title ... ... All

I also have a table called HasVoted

ID Title

And a table called Students

Name ID ... ...

I need to write a query that finds all the Titles in Election where All = yes and checks to make sure that the Title doesn't exist in HasVoted for a given ID ssn.

this didn't work but I thought it was close:

SELECT Title t FROM Elections WHERE Elections.All = 'Yes' AND NOT EXISTS (SELECT ID FROM HasVoted WHERE ID = '" + s + "' AND Title = t);
Nov 15 '05 #1
2 2983
"=?Utf-8?B?RXJpYw==?=" <an*******@discussions.microsoft.com> wrote in
news:66**********************************@microsof t.com:
I have a table called Elections where All is Yes/No

Title ... ... All

I also have a table called HasVoted

ID Title

And a table called Students

Name ID ... ...

I need to write a query that finds all the Titles in Election where
All = yes and checks to make sure that the Title doesn't exist in
HasVoted for a given ID ssn.

this didn't work but I thought it was close:

SELECT Title t FROM Elections WHERE Elections.All = 'Yes' AND NOT
EXISTS (SELECT ID FROM HasVoted WHERE ID = '" + s + "' AND Title = t);


SELECT Title FROM Election E WHERE Elections.ALL = 'Yes' AND NOT EXISTS
(SELECT ID FROM HasVoted V INNER JOIN Students S on V.ID = S.ID WHERE
V.Title = E.Title)

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #2
On Sat, 25 Oct 2003 14:36:00 -0700, Peter Koen
<koen-newsreply&snusnu.at> wrote:
"=?Utf-8?B?RXJpYw==?=" <an*******@discussions.microsoft.com> wrote in
news:66**********************************@microso ft.com:
I have a table called Elections where All is Yes/No

Title ... ... All

I also have a table called HasVoted

ID Title

And a table called Students

Name ID ... ...

I need to write a query that finds all the Titles in Election where
All = yes and checks to make sure that the Title doesn't exist in
HasVoted for a given ID ssn.

this didn't work but I thought it was close:

SELECT Title t FROM Elections WHERE Elections.All = 'Yes' AND NOT
EXISTS (SELECT ID FROM HasVoted WHERE ID = '" + s + "' AND Title = t);


SELECT Title FROM Election E WHERE Elections.ALL = 'Yes' AND NOT EXISTS
(SELECT ID FROM HasVoted V INNER JOIN Students S on V.ID = S.ID WHERE
V.Title = E.Title)


Why join to the Students table at all, it's unnecessary.

SELECT Title FROM Election E WHERE Elections.ALL = 'Yes' AND NOT
EXISTS (SELECT * FROM HasVoted V WHERE V.Title = E.Title)

or

SELECT Title FROM Election E WHERE Elections.ALL = 'Yes' AND Title NOT
IN (SELECT DISTINCT Title FROM HasVoted)

Chris
--
Nov 15 '05 #3

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

Similar topics

9
3899
by: jeanfor | last post by:
I get a http 500 error on all asp pages. When turning off the friendly message box, the message is "Class does not exist". What is the fix for that? This affect all asp pages incling the default...
12
38929
by: zhisol | last post by:
how can i check if file exist in current directory (in javascript)? -- pozdr;) zhisol
1
1745
by: Peter | last post by:
Hi, When my program starts up, it uses MAPILogonEx to connect to the default email profile (set by user). The problem is, if the email profile no longer exist, it would give an error "The...
2
17879
by: adam | last post by:
hello What query shoul I send to SQL serwer ( in transact SQL language ) to check does some database exist on serwer ? It similar to problem "does some table exist in database" - resolve to it...
0
2615
by: Dirk Försterling | last post by:
Hi all, a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following the instructions in the INSTALL file, including dump and restore. All this worked fine without any error (message). ...
4
4045
by: Mike | last post by:
Hi, I am looking for function in .Net library that let me know if exist any file if I specified template. Eg: I specify "*.txt" and if any file (1.txt, 2.txt, .. ) exists then I can get True...
52
7455
by: paytam | last post by:
Hi all Can anyone tell me how can I check that a file exist or no.I mean when you use this commands FILE *fp; if(!fp) //Could not open the file doen't show why it can not open it,may be the...
1
2632
by: sword | last post by:
This my first starting a new topic in English. I want to ask if I want to judge whether a file exists how I should do. I program with C++. Thank you.
3
20872
by: kang jia | last post by:
hi, currently i am doing booking car online and one of the function is cancel and update booking. if the booking number users entered in is not exist. it will redirect the page stating that the...
3
10336
by: moltendorf | last post by:
I copied the files from my "test" database on my old server (MySQL was not running) to my new server ("./mysql/data/test" folder), and after starting the server, SHOW TABLES; shows all of the tables...
0
7264
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,...
0
7316
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...
1
6975
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...
0
7449
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...
0
5562
agi2029
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,...
1
4992
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...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1495
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 ...
0
371
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...

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.