MySQL and Splunk - Select and Join

为君一笑 提交于 2019-12-06 15:58:17

SELECT * is antipattern. If id is only column that exists in both tables you could use:

SELECT *
FROM master_biz.legend_asset
RIGHT JOIN master_custom.custom_app_table_4 
  USING (id);

Otherwise you need to add alias for each column manually:

SELECT a.ID    AS id
       ,a. ... AS ...
       ,t4.col AS ...  
FROM master_biz.legend_asset a
RIGHT JOIN master_custom.custom_app_table_4 t4
  ON a.ID = t4.ID;

Note: You don't need to write table name, you could use table aliases.

EDIT:

what are the differences in the JOIN ON and JOIN USING parts of the code?

USING will return columns that are used in JOIN once:

SELECT *
FROM t1
JOIN t2
  USING(i);

SELECT *
FROM t1
JOIN t2
  ON t1.i = t2.i;

SqlFiddleDemo

Output:

╔════╦════╦═══╗
║ i  ║ b  ║ c ║
╠════╬════╬═══╣
║ 1  ║ 1  ║ 3 ║
╚════╩════╩═══╝

vs.

╔════╦════╦════╦═══╗
║ i  ║ b  ║ i  ║ c ║
╠════╬════╬════╬═══╣
║ 1  ║ 1  ║ 1  ║ 3 ║
╚════╩════╩════╩═══╝
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!