473,654 Members | 3,264 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 2992
"=?Utf-8?B?RXJpYw==?=" <an*******@disc ussions.microso ft.com> wrote in
news:66******** *************** ***********@mic rosoft.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&snusn u.at> wrote:
"=?Utf-8?B?RXJpYw==?=" <an*******@disc ussions.microso ft.com> wrote in
news:66******* *************** ************@mi crosoft.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
3909
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 asp pages in the default directory. Thanks
12
38957
by: zhisol | last post by:
how can i check if file exist in current directory (in javascript)? -- pozdr;) zhisol
1
1761
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 profile name is not valid. Enter a valid profile name", after pressing ok, the email profile wizard will come up. We don't want the error message to come up, instead we want to somehow check if the default email profile exist, if it doesn't exist,...
2
17894
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 is query: use db_silnik IF EXISTS (SELECT * FROM prad) PRINT 'table exist'
0
2641
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). Since then, I found lots of the following in the postmaster output: 2003-11-29 15:19:54 ERROR: large object 4838779 does not exist 2003-11-29 15:20:11 ERROR: large object 4838779 does not exist
4
4066
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 or at least file name . And if does not exist Fasle or empty string. Of course I can use VB6 function Dir, but maybe .Net contains
52
7505
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 file doesn't exist.Now tell me what should I do! Thanks
1
2651
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
20933
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 booking number did not exist or you never book with us. however. i would like to express this "if Not exist" concept in my coding. how should i achieve this. the following is my code: def deleteCar(request): if...
3
10357
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 that are supposed to be there, but running a SELECT * FROM `configuration`; (for example) returns "test.configuration does not exist). I've tried the following repair statement since I'm not too familiar with backing up and restoring data. ...
0
8294
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
8816
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
8709
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
8494
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
8596
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...
0
5627
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
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.