Php 不必要的mysql列更新
我有一个表Php 不必要的mysql列更新,php,sql,Php,Sql,我有一个表Study,包含学生信息,如屏幕截图所示。 然后,我编写了以下查询,只更新研究id=501下一行的研究开始列: UPDATE student,language_german,language_english,study,home_university, host_university,transfer,home_address,host_address,alumni SET firstname = 'Omega', lastname = 'Rugal'
Study
,包含学生信息,如屏幕截图所示。
然后,我编写了以下查询,只更新研究id=501
下一行的研究开始
列:
UPDATE
student,language_german,language_english,study,home_university,
host_university,transfer,home_address,host_address,alumni
SET
firstname = 'Omega',
lastname = 'Rugal',
birthdate = '0000-00-00',
nationality = '',
email= '',
group_name = '',
gender = '',
religion = '',
creation_date = NOW(),
user_id = 43,
german_level = '',
german_status = '',
german_grade = '',
english_level = '',
english_status = '',
english_grade = '',
transfer_type = '',
study_start = "2013-02-01",
matriculation_no = '0',
application_no = '0',
applicationno_old = '0',
overall_status = '',
status_date = '0000-00-00',
comment = ' ',
thesis_status = '',
home_university_name = '',
home_degree_program = '',
home_study_program = '',
host_university_name = '',
host_degree_program = '',
host_study_program = '',
room_status = '',
room_deposit = '0',
room_name = '',
application_letter_home = '0',
motivation = '',
sponsorship = '',
application_letter_abroad = '0',
cv = '0',
result = '',
learning_agreement = '0',
health_insurance = '0',
supervisor_home = '',
supervisor_abroad = '',
visa = '0',
vaccination = '0',
wishlist = '',
home_street = '',
home_co = '',
home_zip = '',
home_city = '',
home_state = '',
home_country = '',
host_street = '',
host_co = '',
host_zip = '',
host_city = '',
host_state = '',
host_country = '',
thesis_grade = '0.0',
average_grade = '0.0',
study_time = '0',
last_email = '',
last_contact = '0000-00-00',
last_info = ''
WHERE
student.student_id = language_german.student_id
AND student.student_id = language_english.student_id
AND study.study_id = home_university.study_id
AND study.study_id = host_university.study_id
AND student.student_id = transfer.student_id
AND student.student_id = home_address.student_id
AND student.student_id = host_address.student_id
AND student.student_id = alumni.student_id
AND student.student_id = 832
其中,student\u id
是每个学生的唯一id
可怕的是,其他行的所有列都被更新为该值
study\u start
,这是不正常的。您的更新远远不止study\u start
。您缺少将学习
链接到特定学生id
的连接。是否有一个university\u id
将student
链接到home\u university
或其他东西
您真的需要加入所有这些表吗?如果你知道研究id
,为什么不能这样做
UPDATE study set study_start='2013-02-01' where study_id=501;
如果您只想更新研究开始列,为什么要将所有其他列设置为特定值?在这个查询中,研究id=501在哪里?我想Wes发现了问题。OP的语句有10个表,但只有8个“连接”,而不是所需的9个。另一种情况是不使用
JOIN
语法,造成灾难性后果。