SELECT DISTINCT tb2.* FROM (SELECT c_id FROM student st INNER JOIN score sc ON sc.s_id =st.s_id where st.s_id ="01") tb1,(select * from student st,score sc WHERE sc.s_id=st.s_id) tb2 WHERE tb1.s_id=tb2.s_id > 1060 - Duplicate column name 's_id' > 查询时间: 0s
时间: 2024-04-27 17:22:39 浏览: 147
SQL_select.rar_sql 语法
在执行上述修改后的查询语句时,出现了 "1060 - Duplicate column name 's_id'" 的错误提示,提示中指出存在重复的列名 "s_id"。这是因为在子查询和主查询中都包含了 student 和 score 两张表,而这两张表中都有一个名为 "s_id" 的列,导致在查询结果中出现了重复的列名。为避免这个错误,可以在主查询中明确指定需要查询的列,并使用唯一的列别名来避免冲突,如下所示:
SELECT DISTINCT tb2.s_id, tb2.s_name, tb2.s_age, tb2.s_gender, tb2.c_id, tb2.score FROM (SELECT c_id FROM student st INNER JOIN score sc ON sc.s_id = st.s_id WHERE st.s_id = "01") tb1, (SELECT st.s_id, st.s_name, st.s_age, st.s_gender, sc.c_id, sc.score FROM student st, score sc WHERE sc.s_id = st.s_id) tb2 WHERE tb1.c_id = tb2.c_id;
修改后的查询语句中,使用了别名对子查询和主查询中的表和列进行了区分,避免了列名冲突的问题。
阅读全文