MySQL cómo unir tablas en dos campos


Tengo dos tablas con los campos date y id. Quiero unirme a ambos campos. He intentado

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

Eso funciona, pero es muy lento. ¿hay una mejor manera de hacer esto?

 85
Author: Eric Leschinski, 2009-01-31

3 answers

JOIN t2 ON t1.id=t2.id AND t1.date=t2.date
 144
Author: womble,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-01-31 04:00:25
JOIN t2 ON (t2.id = t1.id AND t2.date = t1.date)
 31
Author: Chad Birch,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-01-31 03:59:16
SELECT * 
FROM t1
JOIN t2 USING (id, date)

Tal vez necesites usar INNEER JOIN o donde t2.id no es nulo si desea resultados que solo coincidan con ambas condiciones

 21
Author: Eugene Kaurov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-14 09:21:08