...

View Full Version : Running a DB filter query before the main query



sitechooser
03-21-2013, 01:53 PM
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:)

Old Pedant
03-21-2013, 07:52 PM
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?



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum