Query to remove selected records from returned values

I have been scratching my head at a way to query a table of values based on a user id. If that user id has values related to it, minus those values and return the remaining pool of values. This will be used in a application where the values will be displayed on a page using a while loop. Below is the query I have so far, which returns the current selected values for a specific user (just testing). I want the query to remove those values, and return all records in database except those. If any additional information is needed let me know. Thanks!

SELECT distinct f.fundingID, f.fundingDescription
FROM f, sf
WHERE f.fundingID = sf.fundingID
AND sf.studID =  4
ORDER BY fundingDescription ASC;

oh, okay, i think i get it now…

SELECT f.fundingID
     , f.fundingDescription
  FROM f
LEFT OUTER
  JOIN sf
    ON sf.fundingID = f.fundingID
   AND sf.studID = 4
 WHERE sf.fundingID IS NULL
ORDER 
    BY f.fundingDescription ASC;

:slight_smile:

sorry, i had a lot of trouble understanding what you mean by “remove”

how about if you give a few sample rows of data for each of your tables, then show what you want the query to produce

Thank you for your reply!

This is close, but similar to what I had above except you just added the “<> 4” where I had the “= 4”. The problem is that the query you provided and the one I had originally still return all values in the funding_description category. I want to ignore the ones that user id 4 has already selected. As you can see in the first table user Id 4 has selected two items. I want to only return the 9 records that are not related to ID 4. I hope that is a little clearer.

Again thank you for your help and patience, it is much appreciated.

oh, that’s easy

SELECT DISTINCT f.fundingID, f.fundingDescription
  FROM f
INNER
  JOIN sf
    ON sf.fundingID = f.fundingID
 WHERE sf.studID [COLOR="Red"]<>[/COLOR] 4
ORDER 
    BY f.fundingDescription ASC;

no, i don’t mind

:slight_smile:

Sorry “remove” was the wrong wording. Ignore is more inline with what I am trying to accomplish. There are two tables I am pulling from, the sample data is below. My previous query was returning the records with a ID of 4, which would be item7 and item2. I want all values except those values related to ID 4.


funding_selected	studID	fundingID
1	                  3	        1
1	                  3	        2
1	                  3	        11
1	                  3	        5
1	                  4	        7
1	                  4	        2 

fundingID	fundingDescription
1	item1
2	item2
3	item3
4	item4
5	item5
6	item6
7	item7
8	item8
9       item9
10      item10
11	item11

That works…and now instead of just walking away, I am going to look over the code and get back to you if I have any question. I hope you don’t mind :slight_smile:

Thanks again!