MySQL Selecciona todas las columnas de una tabla y algunas de otra tabla


¿Cómo seleccionar todas las columnas de una tabla y solo algunas columnas de otra tabla usando JOIN? En MySQL.

4 answers

Simplemente use el nombre de la tabla:

SELECT myTable.*, otherTable.foo, otherTable.bar...

Que seleccionar todas las columnas de myTable y columnas foo y bar de otherTable.

 346
Author: Tatu Ulmanen,
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
2010-08-16 12:06:02

Necesito más información realmente, pero será a lo largo de las líneas de..

SELECT table1.*, table2.col1, table2.col3 FROM table1 JOIN table2 USING(id)
 32
Author: Simon,
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
2010-08-16 12:08:07

Usando alias para hacer referencia a las tablas para obtener las columnas de diferentes tablas después de unirlas.

Select tb1.*, tb2.col1, tb2.col2 from table1 tb1 JOIN table2 tb2 on tb1.Id = tb2.Id
 2
Author: Himanshu,
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
2018-03-13 14:34:07

Seleccione a.* , b.Aa, b. Ab,b.Ac del cuadro 1 a izquierda unirse a tabla2 b en a.id=b.id

Esto debe seleccionar todas las columnas de la tabla 1 y solo las columnas listadas de la tabla 2. joing por identificación.

 1
Author: Mzila,
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
2017-07-17 15:15:54