0

In a nutshell..

SELECT * 
FROM tbl1 
LEFT OUTER JOIN tbl2 ON tbl1.ID = tbl2.externalRefID 
WHERE tbl1.varref = '12345' OR tbl2.varref = '12345';

With any volume of data in these tables this query takes forever. Yet I need the second table outer joined as it won't often match on the externalRefID. Indexes created for all columns that are referenced but makes no difference as I need an index across multiple tables (is that possible?)

this must be obvious but i can't see the wood for the trees...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
markdrayton
  • 65
  • 1
  • 7

1 Answers1

0

Have you considered refactoring the query into a UNION query?

SELECT *
  FROM tbl1 INNER JOIN tbl2 ON tbl1.id = tbl2.externalRefId
 WHERE tbl2.varref = '12345'
UNION
SELECT *
  FROM tbl1 OUTER JOIN tbl2 ON tbl1.id = tbl2.externalRefId
 WHERE tab.1.varref = '12345'

You might be able to use UNION ALL on this too.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278