Results 1 to 9 of 9

Thread: SQL Help [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147

    Angry SQL Help [RESOLVED]

    I have the following SQL Query:

    VB Code:
    1. SELECT * FROM ALLTAGS INNER JOIN
    2. Trend_Definitions ON ALLTAGS.Real_Tag_NAME = Trend_Definitions.REAL_TAG_NAME

    This passes back all the records in ALLTAGS that exsist in Trend_Definitions.

    How can i change this to return all the recordes from ALLTAGS that DO NOT exist in Trend Definitions?
    Last edited by mik706; Jul 18th, 2005 at 04:47 AM.
    Mik706

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL Help

    Just a guess...

    VB Code:
    1. SELECT * FROM ALLTAGS NOT IN
    2. (SELECT * FROM ALLTAGS INNER JOIN Trend_Definitions ON
    3.  ALLTAGS.Real_Tag_NAME = Trend_Definitions.REAL_TAG_NAME)
    Last edited by dee-u; Jul 13th, 2005 at 03:36 AM.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    New Member
    Join Date
    Jul 2005
    Posts
    4

    Re: SQL Help

    SELECT * FROM ALLTAGS
    WHERE ALLTAGS.Real_Tag_Name NOT IN
    (SELECT Trend_Definations.Real_Tag_NAME FROM Trend_Definitions)

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SQL Help

    I think this is right. Kind of late, so I'm not going to test it.


    VB Code:
    1. SELECT * FROM ALLTAGS LEFT JOIN
    2. Trend_Definitions ON ALLTAGS.Real_Tag_NAME <> Trend_Definitions.REAL_TAG_NAME

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147

    Re: SQL Help

    Cheers guys
    Mik706

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: SQL Help

    You need to use a left join - this forces all records on the left to be included regardless of whether or not there is a corresponding table on the right:
    Code:
    SELECT * FROM ALLTAGS LEFT JOIN
        Trend_Definitions ON ALLTAGS.Real_Tag_NAME = Trend_Definitions.REAL_TAG_NAME
    WHERE Trend_Definitions.REAL_TAG_NAME IS NULL
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL Help

    Quote Originally Posted by mik706
    Cheers guys
    Which code worked?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147

    Re: SQL Help

    Maxperts and visualAds both worked.
    I got "Incorrect syntax near the keywork 'NOT'" when i tried yours and
    dgliennas just returns the first record from ALLTAGS against all the records in Trend_Definitions.
    Mik706

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SQL Help

    Glad that one of them worked for you. We all learned something.
    I learned to try to test before posting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width