子查询语法错误 [英] Error in syntax of subquery

查看:78
本文介绍了子查询语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我是Java的新手,我尝试使用子查询从2个表中检索数据并将其放入函数中,以使用对象将它们插入到另一个表中,但是我的选择子查询语句中存在问题:
这是错误:

Hello.
Iam new to java i try to use sub-query to retrieve data from 2 table and put them inside functions to insert them to another table using object but there is a problem in my select sub-query statement :
this is the error :

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't.idteacher like(select idcourse from course)' at line 1


resultSet=statement1.executeQuery("select t.idteacher , t.Teacher_Name  from Teacher t" +
				"where t.idteacher like(select idcourse from course)" );
		while(resultSet!=null)
		{
			System.out.println(resultSet.getString(1)+" "+resultSet.getString(2));
		}

推荐答案

in替换like:
select t.idteacher , t.Teacher_Name  from Teacher t where t.idteacher in (select idcourse from course)


查看您的like子句.您实际上是从课程表中选择所有记录,并且idteacher列将不可能像数据集一样.我怀疑(看看您的示例),您想显示所有教授某门特定课程的老师,但是您的查询未能指定课程ID.
Look at your like clause. You''re essentially selectiing all records from the course table, and there''s no way the idteacher column is going to be "like" a dataset. I suspect (bby looking at your example) that you want to show all teachers that teach a particular course, but your query fails to specified the course id.


as you writen in you question that way like will never work.

it will select multiple id as you given query (select courseId from Course)
like always work with a single world or statement. you can use in instead of like. i think it will give appropreate result that you want.


这篇关于子查询语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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