Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Running a DB filter query before the main query

    Hi Folks

    I have the following query:

    [code]

    SELECT T.* FROM databasename AS T,

    ( SELECT COUNT(*), column1, column2
    FROM databasename
    GROUP BY column1, column2
    HAVING COUNT(*)>1 ) AS S

    WHERE S.column1 = T.column1
    AND S.column2 = T.column2
    AND column3 NOT LIKE '%entry%'

    ORDER BY T.column1

    [code]

    My problem is that I need to run the:

    [code]

    AND column3 NOT LIKE '%entry%'

    [code]

    filter before the main query.

    Can this be done in one query, or do I have to run the filter first, create a table with the results and then run the main query?

    Thanks in advance for any help offered

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    WHY do you need to do the NOT LIKE test first?

    And in any case, why can't you just put it into the inner SELECT?

    Code:
    SELECT T.* FROM databasename AS T,
        ( SELECT COUNT(*), column1, column2 
          FROM databasename
          WHERE column3 NOT LIKE '%entry%'
          GROUP BY column1, column2 
          HAVING COUNT(*)>1 ) AS S
    WHERE S.column1 = T.column1
    AND S.column2 = T.column2 
    ORDER BY T.column1
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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