473,386 Members | 1,647 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,386 software developers and data experts.

Query Trouble - help required.

G
Hello, I have TWO tables.

TABLE1
-----------
ID ProgramID
01 Program1
02 Program2
03 Program3
04 Program4
....
15 Program15
TABLE2
-----------
ID Username ProgramID
01 Gary Program1
02 John Program2
03 James Program15
04 Gary Program30
05 Gary Program16
Now, we can see in TABLE2 that Gary has joined Program1, Program16 and
Program30, but he has not joined any of the others. How can I return a list
of all the programs GARY has NOT joined? I basically need to return ALL
rows from Table1, WHERE Username <> Gary in Table2.

Not sure if I should be using Subqueries our Joins.

Any help appreciated!!

Gary.
Jul 23 '05 #1
1 1008
On 11/05/2005, G wrote:
How can I return a list of all the programs GARY has NOT joined?


USE test;
DROP TABLE IF EXISTS table1;
CREATE TABLE table1 (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
programid VARCHAR(20) NOT NULL
);
INSERT INTO table1 (id, programid) VALUES
(NULL, 'Program1'),
(NULL, 'Program2'),
(NULL, 'Program3'),
(NULL, 'Program4'),
(NULL, 'Program5');

DROP TABLE IF EXISTS table2;
CREATE TABLE table2 (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(20) NOT NULL,
programid VARCHAR(20) NOT NULL
);
INSERT INTO table2 (id, username, programid) VALUES
(NULL, 'Gary', 'Program1'),
(NULL, 'Gary', 'Program3'),
(NULL, 'John', 'Program3'),
(NULL, 'James', 'Program5');

SELECT
table1.programid
FROM table1
LEFT JOIN table2 ON table2.programid = table1.programid
AND table2.username = 'Gary'
WHERE
table2.id IS NULL;

--
felix
Jul 23 '05 #2

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

Similar topics

1
by: theboss3 | last post by:
I am having trouble with accessing files with query strings. For example the code "require 'template.php?102932'" gives the following error: Warning: main(/www/blog/template.php?102932):...
1
by: Jon | last post by:
Hi there. I'm trying to create a query (or two) that I can use to produce a spreadsheet but I'm having a bit of trouble. I'm using Access 2000. My db is set up like this: Table1: Intrusive...
2
by: Venk | last post by:
hi all, I saw one reply to arun on the subject "Dynamic Query in Ms-Access" by one Mr Rick I found it very useful. Now to extend this solution forward I have the following situation. I...
15
by: KayCee | last post by:
I am using Access 2000 I have three tables I am using to create a query that will be used for a data entry form. Table one - Client List, Table two - Services, Table three - Due Dates. I want...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
1
by: mrkselm | last post by:
Hi, I am stuck with a problem in MS Access which does not occur in SQL Server and I have been banging my head against the wall for a couple of days now trying to resolve it. Namely, when I...
3
by: lostdawg | last post by:
Hi, I am having trouble with the following query. I need to sort from a list of contacts the last date each was contacted. This is to be represented in days so for instance: 0-42 days...
5
by: dougmeece | last post by:
Hello experts, I have an update query that I want to modify records meeting a certain criteria in a table based on information on a form. I am having trouble recognizing the table for a...
1
by: yfangl09 | last post by:
I have one query with a list of people and required courses they have to take and another with the same people and courses they have already taken. How do I generate a query with required courses...
3
by: bob laughland | last post by:
Hi All, I have another SQL question, and this one is going to be difficult to explain. I have a table like this rowid name changed 1 a 1 1 ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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.