MySQL how to join tables on two fields

pedalpete picture pedalpete · Jan 31, 2009 · Viewed 113.9k times · Source

I have two tables with date and id fields. I want to join on both fields. I tried

JOIN t2 ON CONCAT(t1.id, t1.date)=CONCAT(t2.id, t2.date)

that works, but it is very slow. is there a better way to do this?

Answer

womble picture womble · Jan 31, 2009
JOIN t2 ON t1.id=t2.id AND t1.date=t2.date