VideoHelp Forum




+ Reply to Thread
Results 1 to 8 of 8
  1. Member Prot's Avatar
    Join Date
    Dec 2003
    Location
    Oregon
    Search Comp PM
    Ok, all you SQL and MySQL experts. I have a question.
    I need an SQL command to display only the results that return a NULL value. I know I need to use a LEFT JOIN command, but I'm getting all the results, NULLS included.

    This is the command I have:

    SELECT FLNAME, CLTERM, CLYEAR
    FROM tblFaculty F LEFT JOIN tblCLasses C
    ON F.FNUM=C.FNUM

    FLName appears in tblFaculty and CLTERM and CLYEAR are in tblClasses.
    I need to display results where F.Num has no corresponding value to C.FNum. Any Ideas? I'm missing something in my command.

    thanks
    TANSTAAFL
    Quote Quote  
  2. Member
    Join Date
    Nov 2002
    Location
    United States
    Search Comp PM
    Originally Posted by Prot
    Ok, all you SQL and MySQL experts. I have a question.
    I need an SQL command to display only the results that return a NULL value. I know I need to use a LEFT JOIN command, but I'm getting all the results, NULLS included.

    This is the command I have:

    SELECT FLNAME, CLTERM, CLYEAR
    FROM tblFaculty F LEFT JOIN tblCLasses C
    ON F.FNUM=C.FNUM

    FLName appears in tblFaculty and CLTERM and CLYEAR are in tblClasses.
    I need to display results where F.Num has no corresponding value to C.FNum. Any Ideas? I'm missing something in my command.

    thanks
    How about a subquery?

    SELECT FLNAME, CLTERM, CLYEAR
    FROM tblFalculty F, tblClasses C
    where F.FNUM NOT IN
    (Select FNUM from tblClasses)
    Quote Quote  
  3. Member tekkieman's Avatar
    Join Date
    Mar 2004
    Location
    Over the hill
    Search Comp PM
    Check your PM.

    Try:

    SELECT F.FLNAME, C.CLTERM, C.CLYEAR
    FROM tblFaculty F, tblCLasses C
    WHERE F.FNUM=C.FNUM(+)
    Quote Quote  
  4. Member Prot's Avatar
    Join Date
    Dec 2003
    Location
    Oregon
    Search Comp PM
    Originally Posted by tekkieman
    Check your PM.

    Try:

    SELECT F.FLNAME, C.CLTERM, C.CLYEAR
    FROM tblFaculty F, tblCLasses C
    WHERE F.FNUM=C.FNUM(+)
    I tried that, tekkieman. I should say I have to do this SQL command in Access, and Access does not like the (+).

    This query is going to be a 1 to none, and I did not take notes like I should have. Poor me

    Well, the assignment is not due until Wednesday, and I will see another student in the class in one of my other classes. Guess I could ask him. Otherwise I will just have to ask instructor tomorrow.

    Thanks for the replies.
    TANSTAAFL
    Quote Quote  
  5. Member Prot's Avatar
    Join Date
    Dec 2003
    Location
    Oregon
    Search Comp PM
    I found the answer on my own. All I needed was an additional statement.

    SELECT FLNAME, CLTERM, CLYEAR
    FROM tblFaculty F LEFT JOIN tblCLasses C
    ON F.FNUM=C.FNUM
    WHERE CLTERM is NULL
    TANSTAAFL
    Quote Quote  
  6. Greetings Supreme2k's Avatar
    Join Date
    Feb 2003
    Location
    Right Here, Right Now
    Search Comp PM
    I would have suggested that, but for some reason I thought you had already put that in your original query. I could have sworn I saw that WHERE CLTERM is NULL line already.
    Quote Quote  
  7. Member
    Join Date
    Nov 2002
    Location
    United States
    Search Comp PM
    SQL is at times quite counterintuitive, since it's kinda read "backwards".
    Quote Quote  
  8. Member
    Join Date
    Jul 2002
    Location
    Up in yo' bitch.
    Search Comp PM
    Dammit!!! The one question I could've answered and I miss it! Stupid knowing SQL!
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!