基于单列标识符的表合并

时间:2016-11-19 15:11:13

标签: mysql mysql-workbench

第一次提出问题,长时间访问者和自己编写的必要编码,因为Excel并没有削减它!那就是说...请善待,我对此很新。

我有两张桌子,比较'和' himsshospital'在架构' physician_compare'。两个表都有一列“CCN1'”。我想将两个表合并在一起,使用CCN1是匹配的标识符。两个表中都没有主键。我想将重复值保留在'比较'表格,只需在' himsshospital'中添加列表即可。表基于CCN1。在excel中,这相当于在比较'中基于CCN1进行vlookup。表,而不是参考“他的医院”#39;桌子和拖下来。最终产品将是'比较'与相应的医院相关的桌子'添加到其中的列根据CCN1进行匹配。

从我的论坛搜索,我认为我需要进行内部联接,但不断收到错误,例如错误代码:1146表不存在'或者'错误代码:1052列是明确的'。

提前谢谢!

这是我之前尝试的查询,我也包含了表/列设置。我正在使用MySQL Workbench。

`use physician_compare;
 select tbl_names.CCN1
 from tbl_names.compare
 inner join tbl_names.himsshospital
 on tbl_names.CCN1=tbl_names.CCN1;`

SELECT `compare`.`NPI`,
`compare`.`PAC ID`,
`compare`.`Professional Enrollment ID`,
`compare`.`Last Name`,
`compare`.`First Name`,
`compare`.`Middle Name`,
`compare`.`Suffix`,
`compare`.`Gender`,
`compare`.`Credential`,
`compare`.`Medical school name`,
`compare`.`Graduation year`,
`compare`.`Primary specialty`,
`compare`.`Secondary specialty 1`,
`compare`.`Secondary specialty 2`,
`compare`.`Secondary specialty 3`,
`compare`.`Secondary specialty 4`,
`compare`.`All secondary specialties`,
`compare`.`Organization legal name`,
`compare`.`Group Practice PAC ID`,
`compare`.`Number of Group Practice members`,
`compare`.`Line 1 Street Address`,
`compare`.`Line 2 Street Address`,
`compare`.`Marker of address line 2 suppression`,
`compare`.`City`,
`compare`.`State`,
`compare`.`Zip Code`,
`compare`.`Phone Number`,
`compare`.`CCN1`,
`compare`.`Hospital affiliation LBN 1`,
`compare`.`Hospital affiliation CCN 2`,
`compare`.`Hospital affiliation LBN 2`,
`compare`.`Hospital affiliation CCN 3`,
`compare`.`Hospital affiliation LBN 3`,
`compare`.`Hospital affiliation CCN 4`,
`compare`.`Hospital affiliation LBN 4`,
`compare`.`Hospital affiliation CCN 5`,
`compare`.`Hospital affiliation LBN 5`,
`compare`.`Professional accepts Medicare Assignment`,
`compare`.`Reported Quality Measures`,
`compare`.`Used electronic health records`


SELECT `himsshospital`.`Health System ID`,
`himsshospital`.`Health System`,
`himsshospital`.`Health System ID2`,
`himsshospital`.`CCN1`,
`himsshospital`.`Organization Unique Id`,
`himsshospital`.`Organization`,
`himsshospital`.`Organization Primary Service`,
`himsshospital`.`CBSA`,
`himsshospital`.`Address`,
`himsshospital`.`City`,
`himsshospital`.`State/Province`,
`himsshospital`.`Zip Code`,
`himsshospital`.`Fiscal End Date Month`,
`himsshospital`.`Hospital: Parent Organization Control`,
`himsshospital`.`Hospital: Organization Control`,
`himsshospital`.`Organization Phone`,
`himsshospital`.`Website`,
`himsshospital`.`Email Convention`,
`himsshospital`.`Date (Full Update)`,
`himsshospital`.`.`,
`himsshospital`.`Beds: Licensed`,
`himsshospital`.`Beds: Staffed`,
`himsshospital`.`EMRAM Stage (Validated)`,
`himsshospital`.`ER Visits`,
`himsshospital`.`Net Patient Revenues`,
`himsshospital`.`Operating Expense`,
`himsshospital`.`Outpatient Visits`,
`himsshospital`.`Practice: Physicians`,
`himsshospital`.`Admissions`,
`himsshospital`.`Births`,
`himsshospital`.`Cardiology Studies`,
`himsshospital`.`Hospital Physicians: Total`,
`himsshospital`.`Operating Rooms`,
`himsshospital`.`Radiology Studies`,
`himsshospital`.`Total Employees`,
`himsshospital`.`Total Inpatient Revenue`

1 个答案:

答案 0 :(得分:0)

可能是合并是加入betten tbl_names.compare和tbl_names.himsshospital的alis然后你应该为每一侧使用不同的表格 (两侧的表格列tbl_names.CCN1 = tbl_names.CCN1不同)

   use physician_compare;

   select tbl_names.CCN1
   from tbl_names.compare and 
   inner join tbl_names.himsshospital
   on tbl_names.CCN1=himsshospital.CCN1;