更新连接查询不适用于更新已连接表中的记录 [英] Update join query not working for updating record in joined table

查看:62
本文介绍了更新连接查询不适用于更新已连接表中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imgur:互联网的神奇之处 [ ^ ]



Imgur:神奇互联网 [ ^ ]



Imgur:互联网的神奇之处 [ ^ ]



我尝试过:



i尝试使用所有连接左右内部外部完整没有任何工作每次它说0行受影响。

我应该使用插入查询而不是更新对于这个特殊的工作?所以我可以存储从StudentCourse表到考勤表的S_ID和C_ID值?

i我不知道如何编写正确的插入连接查询以使其工作

解决方案

引用:

我应该使用插入查询而不是更新这个特定的工作吗?



这有点说我完全不知道我在做什么这可能是真正的问题。



UPDATE INSERT 查询非常非常不同:一个只更改现有记录,另一个只添加新行到一个表。你认为它们可以互换是令人担忧的 - 你需要在你走得更远之前解决这个问题。



无论如何,最不可能的原因是它不起作用的是您的WHERE条件不正确:如果它没有选择任何行,则没有任何内容被更改或提供给INSERT。

但我们无法访问您的数据,因此我们不知道它能做什么(或应该做什么),也无法测试它。



所以首先要完全删除INSERT代码,然后检查SELECT部分​​单独执行的操作 - 当它正确返回你想要的行时,你可以开始考虑用数据做其他事情!


Imgur: The magic of the Internet[^]

Imgur: The magic of the Internet[^]

Imgur: The magic of the Internet[^]

What I have tried:

i have tried using all joins right left inner outer full none has worked every time it says 0 rows affected.
should i be using insert query instead of update for this particular work?so that i can store S_ID and C_ID values from StudentCourse table to Attendance table?
i am not sure how to write proper insert join query to get it to work

解决方案

Quote:

should i be using insert query instead of update for this particular work?


This kinda says "I have absolutely no idea what I am doing" and that's probably the real problem here.

UPDATE and INSERT queries are very, very different: one changes only existing records, and the other only adds new rows to a a table. That you think they are interchangeable is worrying - and you need to address that before you go much further.

Regardless, the most probable reason it doesn't work is that your WHERE condition is incorrect: if it doesn't select any rows, then nothing gets changed or supplied to INSERT.
But we don't have any access to your data, so we have no idea what it could (or should) do, and no way to test it.

So start by removing the INSERT code completely, and check what the SELECT part does in isolation - when it correctly returns the rows you want, you can start thinking about doing something else with the data!


这篇关于更新连接查询不适用于更新已连接表中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆