473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sql statement help

I have 2 tables:
1) employee - with a unique primary key - employeeid
2) training - with an autonumber primary key, second field employeeid,
third field training

data in employee table:
001
002
003
004
005
....

data in training table
1 001 CPR
2 001 WHMIS
3 002 CPR
4 004 CPR
5 005 WHMIS
....

Basically, I want to write an SQL statement that shows all of the
employees and whether or not they have taken CPR, for example:

001 CPR
002 CPR
003 null
004 CPR
005 null
....

Thanks for your help.

Dec 18 '06 #1
2 1045

gc****@gmail.com wrote:
I have 2 tables:
1) employee - with a unique primary key - employeeid
2) training - with an autonumber primary key, second field employeeid,
third field training

data in employee table:
001
002
003
004
005
...

data in training table
1 001 CPR
2 001 WHMIS
3 002 CPR
4 004 CPR
5 005 WHMIS
...

Basically, I want to write an SQL statement that shows all of the
employees and whether or not they have taken CPR, for example:

001 CPR
002 CPR
003 null
004 CPR
005 null
...

Thanks for your help.
We did this in school, so I've done this absolutely to death. You're
missing a table. The standard setup is like this:
Student---(1,M)---Attendance---(M,1)---Course

and it looks like you only have the first two.

The solution is to create a sort of partial cartesian product between
Course and Student.

SELECT Course.*, Student.StudentID
FROM Course, Student
WHERE Course.CourseName='CPR';

will return a record for each (student,Course='CPR') combination. Now
subtract that result from the Students table, and you're gold.

SELECT Student.FirstName, Student.LastName
FROM Student
WHERE StudentID Not In (SELECT Student.StudentID
FROM Course, Student
WHERE Course.CourseName='CPR');

Dec 18 '06 #2
Beautiful! You're gold Jerry, gold!

Dec 18 '06 #3

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

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
2
by: Little PussyCat | last post by:
Hello, I hope you can help me. We have a SQL Server 2000 database at work, (which works with a VB6 frontend) which grew to a considerable size, so one of my past colleagues sent me this...
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
10
by: John Smith | last post by:
Can you do a Select Statement within a Select Statement? I want to build a query similar to queries built in Access which link to other queries but using only SQL Statements. Is it possible? If...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
4
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" &...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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,...

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.