As others pointed out, you need the appropriate indexes. For this specific query, you can use indexes such as:
( Location, Date ) or ( Date, Location ) (for the WHERE ) as well as ( Title, Variables ) or ( Variables, Title ) (for the join , ON condition)
It would be useful to know exactly the size (i.e. data type) of the location, date, header and variable columns, since a large index is likely to be slower than a small one.
Finally, just a tip: I would not use fantastic comparison constructors like you.
USING (Title, Variables)
probably good, but I would certainly check if
(t1.Location, t1.Date) = ('Location1', 'Date1')
and
(t2.Location, t2.Forecast_date) = ('Location2', 'Date2')
behave as you expect. I would definitely skip EXPLAIN on it and compare the output with a “regular” old-fashioned comparison, for example:
t1.Location = 'Location1' AND t1.Date = 'Date1' AND t2.Location = 'Location2' AND t2.Forecast_date = 'Date2'
You can argue that logically, this is one and the same, and it does not matter - you would be right. But again, the MySQL optimizer is not very smart, and there is always the possibility of errors, especially with functions that are not used much. I think this is such a feature. Therefore, I would at least try EXPLAIN and see if these alternative notations are evaluated equally.
But what BenoCapo pointed out would not be easier to do something like this:
SELECT Title, Variables FROM MyTABLE WHERE Location = 'Location1' AND Date = 'Date1' OR Location = 'Location2' AND Date = 'Date2' GROUP BY Title, Variables HAVING COUNT(*) >= 2
EDIT: I changed HAVING COUNT(*) = 2 to HAVING COUNT(*) >= 2 . See comments (thanks again BenoKrapo)
EDIT: a few days after posting this answer, I found this post from Mark Callaghan, MySQL Architect for Facebook: http://www.facebook.com/note.php?note_id=243134480932 Essentially, it describes how similar but different smart comparisons provide incredible performance due to a MySQL optimizer error. So what I want to say is that you are trying not to use your syntax when you are suffering, perhaps you have fallen into error.