473,799 Members | 2,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

!= operator in queries

I have a query with the following syntax to find students that haven't
voted:

SELECT * FROM Students
WHERE Students.Studen tID != Voted.StudentID

The thing is, the results I'm getting are basically the same as if has
just used 'SELECT * FROM Students' alone. The StudentID list of 'Voted'
is shorter than that of 'Students', as some students haven't voted yet.
Anyone know what I'm wording wrong here?

Thanks,
Aaron
Jul 20 '05 #1
1 1430
Aaron C wrote:
I have a query with the following syntax to find students that haven't
voted:

SELECT * FROM Students
WHERE Students.Studen tID != Voted.StudentID

The thing is, the results I'm getting are basically the same as if has
just used 'SELECT * FROM Students' alone. The StudentID list of 'Voted'
is shorter than that of 'Students', as some students haven't voted yet.
Anyone know what I'm wording wrong here?


Yep, you are selecting rows only from Students table, but using column
from Voted table. It is like comparing the id value to NULL. (Amazing
that it doesn't give syntax error..)

Try something like:
( Not tested, might contain syntax errors, it's 1:30 am here... )

SELECT Students.* FROM Students
LEFT JOIN Voted on Students.Studen tID = Voted.StudentID
WHERE Voted.StudentID IS NULL;

This will find all connections between these two tables. And if there is
no connection (Voted.StudentI D is null), the row is added to result list.
Jul 20 '05 #2

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

Similar topics

5
1499
by: William Gill | last post by:
I am using the % operator to create queries for a db app. It works fine when exact strings, or numbers are used, but some queries need partial matching that use the '%' as a wildcards. So for example the resultant string should be 'WHERE name LIKE %smith%' (would match silversmith, smithy, and smith). Is there any way to get something like searchterm = 'smith' sql += 'WHERE name LIKE %s' % searchterm to return 'WHERE name LIKE...
29
2477
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.
3
19210
by: Mikhail | last post by:
Hi , Does anybody know -how many elements could be in SQL operator IN?. As an example DELETE FROM emp WHERE ename IN (NULL, 'king',...,N); Thank you in advance .
0
1829
by: Vlad | last post by:
I operate with 2 tables: tbLocations and tbDepartments. Both have a column named Town. tbLocations.Town looks like long unique list of different towns world wide: Copenhagen Madrid Roma
6
2265
by: Roger Leigh | last post by:
This code works (GCC 3.3.3): #include <iostream> int main() { bool a = true; std::cout << "True and false\n" << (a == true) ? 't' : 'f'; std::cout << "\n"; return 0;
3
11068
by: Scott Morford | last post by:
I am developing a weed management database for the preserve I work on. One of the queries I'm working on will allow the user to run a query and see which weed patches have NOT been treated in the current calendar year. This query involves two tables. The first contains the static information about the weed patches. The second contains Treatment information. The tables look something like this Static Table fields: Weed_ID (integer)
1
5038
by: jayj0nes | last post by:
I'm querying a Mas90 db via ADO in Access. The following SQL gives me the error "Invalid Operand for Operator: =" "SELECT * from GL_DetailPosting where PostingDate >= '#01/01/2004#'" These other queries work just fine, and they return valid data in the PostingDate field: "SELECT * from GL_DetailPosting" "SELECT * from GL_DetailPosting order by PostingDate DESC" Any ideas where I am going wrong? I've tried just about every syntax I
2
4588
by: David Laub | last post by:
I know there is no C# exponentiation operator. But since the double class is sealed, there seems no way to add the operator override without creating a new class which uses containment (of a double value) This seems a major pain, and would probably wind up being more syntactically messy than just calling Math.Pow(x,y) Surely greater minds than I have already wrestled with this problem...
1
1473
by: Sonu | last post by:
Hi All, How to use an IN operator using asp.net radio control list or checkbox list control For example... Select * from <table name> where name IN ('james','Bob','Jhon') how to use the same in ASP.net? I tried to work with it but cannot get -------> IN ('james','Bob','Jhon') to my SQL statement via asp.net
4
1131
by: xwero | last post by:
Hello i looked in many fora and on many documentation websites but i can't find a way to use the in operator in a mysql query without having an error. select name from users where id in (?) When i parameterize the query like that i get an error saying i don't use the right odbctype. i use int but of course most of the time it's a comma seperated string. If i use the string odbctype i get the same error. "select name from users where id...
0
10482
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...
1
10225
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
10027
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
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
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
6805
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
5463
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
4139
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
2
3759
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.