How to use not exist in my query

Posted by Self-Innovator under Sql Server on 1/11/2013 | Points: 10 | Views : 641 | Status : [Member] | Replies : 2
Consider my tables
table 1:assignmentquestion
select* from assignmentquestion

Output:

id     cid      aid     Question
27 1 21 what is bca?
28 1 21 what is eee?
29 2 22 what is ba ?
30 2 22 what is aa?
31 4 23 what is bsc?
32 4 23 what is bbb?
35 1 24 what is dddd?
36 1 24 what is ggg?
37 4 23 what is ccc?
38 9 25 what is v?
39 1 21 what is ggg?
40 1 21 what is sas?
41 1 21 What is Inheritance?


table 2:assignmentanswer

select * from assignmentanswer


OutPut:


id sid aid ans date
138 1 21 1 2013-01-11 12:49:56.717 27
139 1 21 2 2013-01-11 12:49:57.123 28
140 6 24 ddd1 2013-01-11 12:50:44.610 35
141 6 24 ggg2 2013-01-11 12:50:45.010 36
142 6 21 sd 2013-01-11 15:27:24.427 27
143 6 21 asd 2013-01-11 15:27:24.850 28
144 6 21 fgdfgf 2013-01-11 15:27:25.277 39
145 6 21 dghfgfh 2013-01-11 15:27:25.700 40


My Query to get the last record from table assignmentquestion where the student have not attended the question.
41 1 21 What is Inheritance?

select asm.id,asm.aid,asm.question,asn.id,asn.aid,asn.answer from assignmentquestion asm
inner join assignmentanswer asn on asm.aid=asn.aid and asm.id=asn.qid where asn.sid=6 and asn.aid=21


Output:
id aid Question id aid ans
27 21 what is bca? 142 21 sd
28 21 what is eee? 143 21 asd
39 21 what is ggg? 144 21 fgdfgf
40 21 what is sas? 145 21 dghfgfh



My expected output is to get the last record of assignmentquestion table as
41 1 21 What is Inheritance?

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Shubham on: 1/12/2013 [Member] Starter | Points: 25

Up
0
Down
hi!!! Self-Innovator
can u plz clear what do u want to say and what do u want to select????

Thanks&Regards:-
Shubham Choudhary
Software Engineer
www.facebook.com/shubham.kunar

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prashikudupi on: 1/30/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Columns shown in Output and in Query are not matching.
select asm.id,asm.aid,asm.question,asn.id,asn.aid,asn.answer from assignmentquestion asm
inner join assignmentanswer asn on asm.aid=asn.aid and asm.id=asn.[b]qid[/b] where asn.sid=6 and asn.aid=21

Please re-check the the query.

SQL Tips and Tricks in http://sqlbay.blogspot.in/ 


Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response