mysql select语句where条件能不能继续嵌套select?

判断商品是否存在的问题。
比如说 SELECT id,name,age,class FROM user where id ='$id' and class=select c.class_id from class where c.class_name=$class;
表单中用户输入的class是中文,不是其对应的id值,而user表中只存了class的id

首先明确,where中可以继续使用select,但是需要使用括号,比如
select id,name from tab1 where id=(select id from tab2 where name='苹果')
另外,这种情况,完全可以用表关联,写成一个不需要子查询的sql,比如
select a.id,a.name from tab1 a,tab2 b where a.id=b.id and b.name='苹果'
温馨提示:答案为网友推荐,仅供参考
相似回答