插入内部连接到表中
我一直在尝试执行带有另一个表的内部连接的表中插入。我试图使用以下的内部加入,但这无效。我不太确定哪个更合适,无论使用内部连接还是左JOIN
INSERT INTO ticketChangeSet (Comments, createdBy, createdDateTime)
VALUES ('Test', 'system', CURRENT_TIMESTAMP)
INNER JOIN tickets ON ticketChangeSet.ticket_id = tickets.id
WHERE tickets.id BETWEEN '3' AND '5'
样本数据:
门票表
id comment createdDateTime closeDateTime createdBy
2 NULL 2022-07-05 15:36:20 2022-07-05 16:21:03 system
3 NULL 2022-07-05 15:36:20 2022-07-05 16:21:03 system
4 NULL 2022-07-05 15:36:20 2022-07-05 16:21:03 system
5 NULL 2022-07-05 15:36:20 2022-07-05 16:21:03 system
Ticketchangeset表
id comments createdBy createdDateTime ticket_id
1 Ticket not resolved system 2022-07-05 15:59:01 2
,我想插入此值('ticke not not vasted','system','2022-07-05 15:59:01')从售票表中的ticket_id ticket_id ticket_id表中
I've been trying to execute insert into a table with an inner join with another table. I tried to use inner join as below but it didn't works. I'm not very sure which is more suitable whether to use INNER JOIN or LEFT JOIN
INSERT INTO ticketChangeSet (Comments, createdBy, createdDateTime)
VALUES ('Test', 'system', CURRENT_TIMESTAMP)
INNER JOIN tickets ON ticketChangeSet.ticket_id = tickets.id
WHERE tickets.id BETWEEN '3' AND '5'
Sample data:
tickets table
id comment createdDateTime closeDateTime createdBy
2 NULL 2022-07-05 15:36:20 2022-07-05 16:21:03 system
3 NULL 2022-07-05 15:36:20 2022-07-05 16:21:03 system
4 NULL 2022-07-05 15:36:20 2022-07-05 16:21:03 system
5 NULL 2022-07-05 15:36:20 2022-07-05 16:21:03 system
ticketChangeSet table
id comments createdBy createdDateTime ticket_id
1 Ticket not resolved system 2022-07-05 15:59:01 2
Basically, I want to insert this value ('Ticket not resolved', 'system', '2022-07-05 15:59:01') into the ticketChangeSet table for ticket_id 3 to 5 from ticket table
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需直接从Dillissue(或从票证上 - 不确定)选择行,然后将您的常数作为列值提供。
请注意终结者的语句终结器和模式名称的使用 - 这两个最佳实践。我还假设ID列是数字,并删除了围绕这些过滤器值的字符串定界器。我省略了加入,因为它似乎并不需要。据推测,差异和门票之间的关系是1:1,因此内部联接无济于事。但是,也许您需要在ID值范围内包含来自票证的行,但在不同的ID值中可能不存在?因此,请尝试
,但是这一切似乎很可疑。我认为逻辑中至少缺少一个关键列 - 也许不止一个。
更新。现在,您更改了表名,添加了更多列,然后更改了过滤器。您仍然将字符串常数用于数字列 - 一个坏习惯。
我把它留给你填写缺失的碎屑。
Just select the rows directly from differIssue (or maybe from Tickets - not certain) and supply your constants as the column values.
Notice the statement terminator and the use of schema name - both best practices. I also assumed that the ID column is numeric and removed the string delimiters around those filter values. I left out the join because it did not seem required. Presumably the relationship between differIssue and Tickets is 1:1 so an inner join does nothing useful. But perhaps you need to include rows from Tickets for that range of ID values but which might not exist in differIssue? So try
But this all seems highly suspicious. I think there is at least one key column missing from the logic - and perhaps more than one.
Update. Now you've changed the table names, added more columns, and changed the filter. You still use string constants for a numeric column - a bad habit.
I leave it to you to fill in the missing bits.