Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
my query goes like this
SELECT DISTINCT (s.sid),class,division,fatmobile,rollno,stdname,regno FROM termdetails t JOIN studentdetails s WHERE t.sid != s.sid AND s.class = '" + ClassWiseDrop1.SelectedValue + "' AND s.division = '" + ClassWiseDrop2.SelectedValue + "'

this query returns all the details (in which sid is present in table termdetails also coming) so here not equals operator not working. how can i resolve my problem
can any one please help me.
thanks in advance
Posted
Updated 30-Mar-11 20:09pm
v2

You are misunderstanding how a join works. That will actually produce something close to an outer join, only missing the rows where the two match. I think what you want to do is a simple select on termdetails, something like
select * from termdetails where not sid in (select sid from studentdetails)
(In versions before 5 you have to construct the in-list yourself. And note that I haven't tested this so something might be wrong.)

Your question is not totally clear about what you're actually trying to do though.
 
Share this answer
 
SELECT DISTINCT (s.sid),class,division,fatmobile,rollno,stdname,regno FROM termdetails t WHERE t.sid NOT IN ( SELECT s.sid from studentdetails s WHERE (s.class = '" + ClassWiseDrop1.SelectedValue + "' AND s.division = '" + ClassWiseDrop2.SelectedValue + "'))


Why dont you try making use of the above code. I think this might help. Or try using the UNION operator if you come across any more problems.

NOT IN Usage[^]
NOT IN Usage 2[^]

Here is an example of how NOT IN can be used.
 
Share this answer
 
The != (not is) operator in SQL is <>

SQL
SELECT ID FROM TableName WHERE (Name <> 'banana')
 
Share this answer
 
Comments
tulasiram3975 31-Mar-11 4:12am    
Dear Sir,
I tried With Both The Operators (<> or !=)
but result will be same
Here What I need is
in my two tables i Placed one Unique Column called (sid) I need to Get The Values from table1 in which Sid Not Presented In Table2
Could You Please Help Me Out
thanks in advance
Wayne Gaylard 31-Mar-11 5:02am    
both operators are recognised equally by MySQL, and are functionally equivalent.
tulasiram3975 31-Mar-11 6:08am    
Ok Sir,
My Problem Is It Returns All Details
I Need The Values Which Is Not Present In Table2
Please Help Me
Thank You
I think the problem lies with t.sid. To include a field in a conditional clause, it has to be returned in the SELECT clause, and t.sid is not in the field list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900