473,569 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ 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 1695
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_co urse,t_couse_st udent
where t_studends.stud ent_id = t_course.studen t_id AND t_couse_student .course_id =t_course.cours e_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_nam e(FK)
tc.course_id(PK )-tcs.course_id(F K)
Query-1
select distinct ts.student_name
from t_students ts,t_course tc,t_course_stu dent tcs
where ts.student_id=t cs.student_id and tc.course_id=tc s.course_id
and tcs.course_id not in(select course_id from t_course where course_name='ex cel')

Output-student1,studen t2
Explanation-student1 's name comes as it takes 'word' course also besides 'excel'.student 2 takes 'word'.and student3 wont b there as u hv nt mentioned its corresponding course in t_course_studen t.

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_stu dent tcs
where ts.student_id=t cs.student_id and tc.course_id=tc s.course_id
and ts.student_id not in (select student_id from t_course_studen t where course_id =(select course_id from t_course where course_name='ex cel'))

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
10179
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 database table, using dynamic sql. Executing 'EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;' the error code -2149 is returned That means...
2
2458
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. Here it is: mySQL server: version "4.0.20-standard" on localhost hardware : 1.8 MHz Pentium 4 with 512 cache and 512 MB 266MHz RAM and 40 MB...
7
11898
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 ] = "US"; is the SQL column name (because it sarts with 2?). As the statement is shown I get the error message: Unclosed quotation mark before the...
3
6436
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too...
1
3654
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 "access_log", the referential integrity triggers generate these queries: SELECT 1 FROM ONLY "public"."application_type" x
5
6888
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 the described properties. If I use the same statement in a select into statement (see the second select) I get several datasets with the described...
2
5166
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. -------------------------------------------------------- SELECT b.ISBN, b.Title, b.SmallImage, f.idForSale, count(f.idForSale) FROM books b, forsale f
4
2452
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 value of an option in a select statement: <select id="usertypes" multiple="multiple"> <option value="0033">data1</option>
1
21652
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 "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan" case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb" End Select
4
10570
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 the fields and noticed that if I don't check a box, then the query will look specifically in the table for where the applicable field is FALSE. This...
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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...
0
8122
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...
1
7673
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...
0
7970
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...
0
6284
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...
1
5513
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...
1
2113
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
0
937
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...

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.