【发布时间】:2018-02-10 18:37:53
【问题描述】:
我有三张桌子 - MainTable、Country 和 VisaType。
表 1 - 主表:
---------------------------------------------------------------
| MainTableID | ApplicantName | CountryID | VisaTypeID | Date |
---------------------------------------------------------------
表 2 - 国家:
-----------------------
| CountryID | Country |
-----------------------
| 1 | Japan |
| 2 | Georgia |
-----------------------
表 3 - 签证类型
-------------------------
| VisaTypeID | VisaType |
-------------------------
| 1 | B2 |
| 2 | H1-B |
-------------------------
我想得到以下结果:
-------------------------------------------------------------------------
| MainTableID | ApplicantName | CountryID | VisaTypeID | Date |
-------------------------------------------------------------------------
| 1 | George | 2 | 1 | 2018 - 02 - 22 |
-------------------------------------------------------------------------
我正在这样做:
INSERT INTO MAINTABLE (ApplicantName, CountryID, VisaTypeID, Date)
SELECT 'George', CountryID, VisaTypeID, '2018-02-22'
FROM Country, VisaType
WHERE Country.Country = 'Georgia'
AND VisaType.VisaType = 'B2'
问题是:对于这项任务应该有什么更好的解决方案,是否可以使用内部连接来实现?
【问题讨论】:
标签: sql sql-server sql-insert