473,466 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Select Statement Problem

11 New Member
I have 3 tables

t_studends
---------
student_id student_name
---------- ------------

1 Student1
2 Student2
3 Student3


t_course
---------
course_id course_name
-------- -----------
1 word
2 excel
3 outlook
4 powerpoint

t_couse_student
---------------
id student_id course_id
-- ---------- ---------
1 1 1
2 1 2 *************
3 2 1

when i search for students whom didn't took excel for example, the query returns all 3 students, i want it

return only student 2,3 because student 1 took that course.

can u help me plz...
Aug 2 '06 #1
7 1690
Banfa
9,065 Recognized Expert Moderator Expert
Post the query you are/where using
Aug 2 '06 #2
farid25
11 New Member
query am using
-----------------
select *
from t_studends,t_course,t_couse_student
where t_studends.student_id = t_course.student_id AND t_couse_student .course_id =t_course.course_id AND t_course.course_id <> 2
Aug 2 '06 #3
lipsa
35 New Member
helo farid,i m a beginner wid 3 months work exp :) ,but trying to help u,hope it will be useful.i m writing 2 queries.i am assuming data frm ur table

assumption-ts.student_name(PK)-tcs.student_name(FK)
tc.course_id(PK)-tcs.course_id(FK)
Query-1
select distinct ts.student_name
from t_students ts,t_course tc,t_course_student tcs
where ts.student_id=tcs.student_id and tc.course_id=tcs.course_id
and tcs.course_id not in(select course_id from t_course where course_name='excel')

Output-student1,student2
Explanation-student1 's name comes as it takes 'word' course also besides 'excel'.student2 takes 'word'.and student3 wont b there as u hv nt mentioned its corresponding course in t_course_student.

Query-2

Note-this query return name of the students who have not taken 'excel'(with other course like student1) at all

select ts.student_name
from t_students ts,t_course tc,t_course_student tcs
where ts.student_id=tcs.student_id and tc.course_id=tcs.course_id
and ts.student_id not in (select student_id from t_course_student where course_id =(select course_id from t_course where course_name='excel'))

Output-student2
Regards,
Lipsa(plz excuse me and provide right solution if i m wrong :) )
Aug 3 '06 #4
Banfa
9,065 Recognized Expert Moderator Expert
Thanks lipsa, I'm not a great SQL expert and I had got as far as working out that negative requirements where not easy. From your solution I see that this was probably a justified conclusion.
Aug 3 '06 #5
lipsa
35 New Member
sorry Banfa,i dont get u clearly.
but if the solution serves the purpose..umm...its ok..:-))
Aug 3 '06 #6
farid25
11 New Member
lipsa, thanks very very much
it works now , thanks again for your help
Aug 3 '06 #7
lipsa
35 New Member
My pleasure Farid :)
Regards,
Lipsa
Aug 4 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
2
by: ghasem | last post by:
Dear mySQL community, I have once again turned to the user groups for a problem I cannot solve myself! Atually, I have read all I can from the newsgroups on this but I could not solve it myself....
7
by: CharlesEF | last post by:
Hi All, I have run into another problem that is eating my lunch. Should be simple but I am having one heck of a time. Please look at this SELECT statement: SELECT FROM States WHERE ] =...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
5
by: Daniel Wetzler | last post by:
Dear MSSQL experts, I use MSSQL 2000 and encountered a strange problem wqhile I tried to use a select into statement . If I perform the command command below I get only one dataset which has...
2
by: scole954387 | last post by:
Hi, I have a problem. I have written a SQL statement that has a nested select case statement on the 'where' clause to condition the results. ...
4
by: Matt Ratliff | last post by:
Hello, I would appreciate any assistance you have with the following problem: I have (as an example) an array of values as follows: arrayvalues=new Array("0001","0003","0005") where each is the...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
4
by: The.Daryl.Lu | last post by:
Hi, Have a bit of a problem... I've created a form in Access and will use the form for a user to query a table based on the selected fields. The problem lies in that I was using checkboxes for...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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,...
0
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
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 ...

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.